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.
find() function returns an instance of Mongoose's Query class. The Query class represents a raw CRUD operation that you may send to MongoDB. It provides a chainable interface for building up more sophisticated queries. You don't instantiate a Query directly, Customer.
It just means that your new document will have a field with "done" as key and "false" boolean as value.
The value of the $in operator is an array that contains few values. The document will be matched where the value of the breed field matches any one of the values inside the array.
The Mongoose Query class provides a chaining interface for finding, updating, and deleting documents.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With