In node.js, when I use Mongoose:
is it possible to only fetch some of the values of a large object?
Is it possible to only update some of the values?
To fetch only certain fields, pass a string of field names as the second parameter in your find
:
// Include the first and last properties, and exclude _id
Model.find({}, 'first last -_id', callback)
or use the object notation as described here:
Model.find({}, {first: 1, last: 1, _id: 0}, callback)
To only update some of the properties, use an update
with a $set
modifier:
// Only update the name property
Model.update({_id: 12345}, {$set: {name: 'New name'}}, callback);
I think with version 3.0.0 this was updated to
Model.find({}, 'first last', callback);
Where first
and last
are property names on the Model.
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