How to select a specific field with Mongoose find?

Sometimes, we want to select a specific field with Mongoose find.

In this article, we’ll look at how to select a specific field with Mongoose find.

How to select a specific field with Mongoose find?

To select a specific field with Mongoose find, we can use the schema find method with the field we want to select.

For instance, we write

dbSchemas.SomeValue.find({}, 'name', (err, someValue) => {
  if (err) {
    return
  }
  console.log(someValue);
});

to call dbSchemas.SomeValue.find to select the 'name' property.

Then someValue would be the value of the name property.

Conclusion

To select a specific field with Mongoose find, we can use the schema find method with the field we want to select.