How to return certain fields with .populate() from Mongoose?

Sometimes, we want to return certain fields with .populate() from Mongoose.

In this article, we’ll look at how to return certain fields with .populate() from Mongoose.

How to return certain fields with .populate() from Mongoose?

To return certain fields with .populate() from Mongoose, we can call populate with the fields we want to populate.

For instance, we write

Model
  .findOne({
    _id
  })
  .populate('field', 'name')

to call populate with 'field' and 'name' to populate the field and name fields in the returned documents.

Conclusion

To return certain fields with .populate() from Mongoose, we can call populate with the fields we want to populate.