Model.find()
Parameters
- filter «Object|ObjectId»
[projection] «Object|String|Array<String>» optional fields to return, see
Query.prototype.select()
[options] «Object» optional see
Query.prototype.setOptions()
[callback] «Function»
Returns:
- «Query»
Finds documents.
Mongoose casts the filter
to match the model’s schema before the command is sent. See our query casting tutorial for more information on how Mongoose casts filter
.
Examples:
// find all documents
await MyModel.find({});
// find all documents named john and at least 18
await MyModel.find({ name: 'john', age: { $gte: 18 } }).exec();
// executes, passing results to callback
MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});
// executes, name LIKE john and only selecting the "name" and "friends" fields
await MyModel.find({ name: /john/i }, 'name friends').exec();
// passing options
await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .