How to avoid other languages?

languages: {$all:["English","Japanese"]}

It is returning documents with “English”,“Japanese” and other languages also.
How can I avoid other language? How can I do a strict check ?


Hi @Gaurav_Yadav, :wave:
Please note that the lab asks you to find movies where:

  • languages contains “English” and “Japanese”

And $all will work perfectly for that case.

But, in case you are still wondering how to strict check an array with only the values mentioned in the array, you can try the following:

    "$and": [
        "languages": {
          "$all": ["English", "Japanese"],
        "languages": {
           "$size": 2 

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer


Another way to an even stricter check than what @SourabhBagrecha gave you is simply:

languages : [ "English" , "Japanese" ]

but this will not match

languages : [ "Japanese",  "English" ]

but @SourabhBagrecha will. But for this lab:

is indeed

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.