Consider the following code
const mongoose = require('mongoose');
main().catch((err) => console.log(err));
const Model = mongoose.model('collection', new mongoose.Schema({ ... }));
async function main() {
const connection = await mongoose.connect(`mongodb://localhost:27017/DB`);
// Method 1
const doc1 = await Model.find({ key: 'value' });
console.log(doc1);
// Method 2
const doc2 = await Model.find().where('key').equals('value');
mongoose.connection.close();
console.log(doc1);
}
Model.find() returns a <Query> Object which is chainable.
Q1• What is a <Query> Object. Is it a promise?
Q2• What is the difference between Method1 and Method2 ?