mongoose findone example
Example 1: mongoose find() example
await MyModel.find({});
await MyModel.find({ name: 'john', age: { $gte: 18 } }).exec();
MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});
await MyModel.find({ name: /john/i }, 'name friends').exec();
await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();
Example 2: findbyid mongoose
await Adventure.findById(id).exec();
Adventure.findById(id, function (err, adventure) {});
await Adventure.findById(id, 'name length').exec();
Example 3: callback mongoose get value from document
var query = Model.find({});
query.where('field', 5);
query.limit(5);
query.skip(100);
query.exec(function (err, docs) {
});
Example 4: mongoose find
const query = Customer.find().sort({ name: 1 }).limit(1);
query.getOptions();