Difference between $all and $and

For lab1 if I use $all operator for languages I am getting correct result(23), where as if I use $and I am getting wrong result(9 documents). I don’t understand the dfference between these two operators. Why am I getting two different results.

languages: {$all: [“English”,“Japanese”]}

$and: [{“languages”:[“English”,“Japanese”]}]}}]

1 Like

Hi @Shopana_65238,

The real difference here is between these two:
languages: {$all: [“English”, “Japanese”]}
languages: [“English”, “Japanese”]

… the $and has no effect. Hopefully you’ll be able to make some conclusions from the above.

Hi @Shopana_65238,

Using $all operator ensure that all the elements specified between are present in the array and there may/may not be some other eelements present in languages array.
Using $and we restrict our search to those elements that only have “English” and “Japanese” fields in the languages array.

Please refer to the following documentation for more details:

Please let me know if you have any questions.


1 Like