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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *