Categories
JavaScript Answers

How to use Node Mongoose Find with multiple conditions?

Spread the love

To use Node Mongoose Find with multiple conditions, we put all the conditions in one object.

For instance, we write

User.find(
  { $or: [{ region: "NA" }, { sector: "Some Sector" }] },
  (err, user) => {
    if (err) {
      res.send(err);
    }
    console.log(user);
    res.json(user);
  }
);

to call find with an object with $or set to an array of conditions we’re looking for.

And we get the result from user in the callback.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.