Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  98] [ 6]  / answers: 1 / hits: 148009  / 13 Years ago, sat, march 3, 2012, 12:00:00

I'm pretty confused with the use of the select method. This is how I use it, and it's wrong:



Transaction.find({username : user.username}).select('uniqueId', 'confirmation_link', 'item_name', 'timeout', 'username', function(err, txs){
callback(txs);
});


What I'm trying to achieve is simply to select from the transactions in the database the ones with that username and I want to take out just the fields listed in the select method. Can anyone point out how should I use the select method? Thanks.


More From » node.js

 Answers
-2

the docs say you can achieve this like so:



Mongoose v4.0



// Retrieving only certain fields

Model.find({}, 'first last', function (err, docs) {

});


old outdated API



// Retrieving only certain fields

Model.find({}, ['first', 'last'], function (err, docs) {
// docs is an array of partially-`init`d documents
// defaults are still applied and will be populated
});


so you can do this without select().


[#87067] Friday, March 2, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamaal

Total Points: 515
Total Questions: 102
Total Answers: 107

Location: France
Member since Thu, May 6, 2021
3 Years ago
;