Query()

Parameters
  • [options] «Object»
  • [model] «Object»
  • [conditions] «Object»
  • [collection] «Object» Mongoose collection

Query constructor used for building queries. You do not need to instantiate a Query directly. Instead use Model functions like Model.find().

Example:

  1. const query = MyModel.find(); // `query` is an instance of `Query`
  2. query.setOptions({ lean : true });
  3. query.collection(MyModel.collection);
  4. query.where('age').gte(21).exec(callback);
  5. // You can instantiate a query directly. There is no need to do
  6. // this unless you're an advanced user with a very good reason to.
  7. const query = new mongoose.Query();