Categories
JavaScript Answers

How to exclude one particular field from a collection in Mongoose and JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.