Chapter 3: Deeper Dive on the MongoDB Query Language Array Operators: $all


On the lecture when you use the $all: operator with 3 options it shows all arrays that contains the all 3 options,

Hi @Jose_20145,

The $all operator selects the documents where the value of a field is an array that contains all the specified elements in the query.

Let’s understand the query which we have implemented in the Lecture: Array Operators: $all.

db.movieDetails.find({genres: {$all: ["Comedy", "Crime", "Drama"]}}, {_id: 0, title: 1, genres: 1}).pretty()

When we execute this query, it will return all those document whose genres field contains all these three values “Comedy”, “Crime” and “Drama”.

Note: It will also return those documents which has any other value present in the genres field besides the three mentioned values.

If you still have any query, please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

1 Like