With size out of the way, let's now have a look at all. For that, I will use the data
I also used in the assignment,
so for me that is stored in the box office database.
So let's use box office
and there if I have a look at all collections, we see there is the movie starts collection.
So I'll work with that movie starts collection,
moviestarts,
let's quickly have a look into it without any filter to see what's in there,
we got three movies and now let's say I want to find movies that have a genre of exactly thriller and
action but I don't care about the order because I've got two movies, this one and this one and they both
only got thriller and action.
The problem I will have is if I use my movie starts here and I find my movies by the genre and I
say it has to be exactly equal to action and thriller, then I will only find one document because only
this document is exactly equal to action being the first element and thriller being the second element
which is what I specified here.
But what if I don't care about the order? Well then, the all operator can help you. For this,
I simply wrap my array in a document where I use $all as operator and that operator receives
my array then and we also need to close that extra curly brace.
What this will do is it will now search genre for these keywords and it will make sure that these items
do have to exist in genre and these items could be numbers, could be embedded documents, could be other arrays
even, doesn't matter
but it ensures that these two elements exist in a genre
but it doesn't care about the order. And therefore now I find both documents even though the order is
different within genre.
So all is really useful if you don't care about the order,
you just want to make sure that all fields are included
but the order does not matter for you.