Sometimes, we want to exclude one particular field from a collection in Mongoose and JavaScript.
In this article, we’ll look at how to exclude one particular field from a collection in Mongoose and JavaScript.
How to exclude one particular field from a collection in Mongoose and JavaScript?
To exclude one particular field from a collection in Mongoose and JavaScript, we call the select method.
For instance, we write
const products = await Product.find().select(["-image"]);
to call select with an array with "-image" to exclude the image field from the returned results.
Conclusion
To exclude one particular field from a collection in Mongoose and JavaScript, we call the select method.