Array Operators

📌 $all

Matches array fields against an array of elements. All the elements that you are looking for must be in this array field.

db.movieDetails.find({“genres”: {$all:[“Comedy”, “Drama”]}})

📌 $size

We use $size to match documents based on the length of an array.

db.movieDetails.find({“genres”: {$size: 2}})

📌 $elemMatch

This one is used to find one element in an array that match all the criteria specified.

db.movieDetails.find({“boxOffice”: 
                     {$elemMatch: 
                                {“country”: “Germany”, “revenue”: {$gt: 17}}})

Last updated

Was this helpful?