According to the field of the array, it is Mongo that provides the $eq operator, which can be controlled through the array as well as the value.
db.collection.find({ "hobbies": {$eq: [ "singing", "Music" ] }});
Also $eq checks the order in which you specify the elements.
If you use the request below:
db.coll.find({ "hobbies": { "$size" : 2, "$all": [ "2", "1" ] } });
Then the exact match will not be returned. Suppose you requested:
db.coll.find({ "hobbies": { "$size" : 2, "$all": [ "2", "2" ] } });
This query will return all documents having element 2 and having size 2 (for example, it will also return a document with hobies :[2,1] ).
source share