MongoDB: what is the difference between $elemMatch and $and to find objects inside array?
14:53 14 Oct 2019

Is there any logical difference between the usage of the query operator $and

db.collection.find({$and: [{"array.field1": "someValue"}, {"array.field2": 3}]})

and the usage of the projection operator $elemMatch

db.collection.find({array: {$elemMatch: {field1: "someValue", field2: 3}}})

to find documents which contain the object fields inside an array?

mongodb mongodb-query