How to call Mongoose find with multiple conditions with JavaScript?

Sometimes, we want to call Mongoose find with multiple conditions with JavaScript.

In this article, we’ll look at how to call Mongoose find with multiple conditions with JavaScript.

How to call Mongoose find with multiple conditions with JavaScript?

To call Mongoose find with multiple conditions with JavaScript, we call the find method with an object with all the conditions.

For instance, we write

User.find({ region: "NA", sector: "Some Sector" }, (err, user) => {
  if (err) {
    console.log(err);
  }
  console.log(user);
});

to search for a User entryt with region set to 'NA' and sector set to 'abc'.

We get errors for the query from err.

And we get the query result from user.

Conclusion

To call Mongoose find with multiple conditions with JavaScript, we call the find method with an object with all the conditions.