mongodb find $and code example

Example 1: mongodb find with gt

{field: {$gt: value} }

Example 2: find with $or in mongobd

db.inventory.find( { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] } )

Example 3: mongodb findmany

model.find({
    '_id': { $in: [
        mongoose.Types.ObjectId('4ed3ede8844f0f351100000c'),
        mongoose.Types.ObjectId('4ed3f117a844e0471100000d'), 
        mongoose.Types.ObjectId('4ed3f18132f50c491100000e')
    ]}
}, function(err, docs){
     console.log(docs);
});

Example 4: find by $in mongo

db.persons.find( { name: { $in: [ "John", "David", "Sarah" ] } } )

Example 5: and in mongodb

{ $and: [ <expression1>, <expression2>, ... ] }

Example 6: mongodb find multiple fields

{ <field1>: <value>, <field2>: <value> ... }