Sometimes, we want to use the Mongoose use of select method in Node.js.
In this article, we’ll look at how to use the Mongoose use of select method in Node.js.
How to use the Mongoose use of select method in Node.js?
To use the Mongoose use of select method in Node.js, we can use the find
method with the fields we want to return in the results.
For instance, we write
User.find({}, "first last", (err, user) => {
//...
});
to call User.find
with 'first last'
to get the User
results and return the first
and last
properties in each result only.
We get the returned query results from the user
parameter.
Conclusion
To use the Mongoose use of select method in Node.js, we can use the find
method with the fields we want to return in the results.