Why the first question on $match in Chapter 1 is inappropriate!

This is a discussion regarding the following question from excersice.

Help MongoDB pick a movie our next movie night! Based on employee polling, we’ve decided that potential movies must meet the following criteria.

  • imdb.rating is at least 7
  • genres does not contain “Crime” or “Horror”
  • rated is either “PG” or “G”
  • languages contains “English” and “Japanese”

I had to spend days trying without being able to solve and I want to share with others why this may not be a perfect questions and you have to assume a lot of things to get exactly what the answer demands.

  1. First of all, genres is an array, the only answer that will work here is if you use an $and expression with genre = Crime and genre = Horror. But this is stupid. I have been trying to do this for a long while and was getting different output and thus, was stuck.

genres: {$elemMatch: {$ne: “Crime”, $ne:“Horror”} } – but it didn’t work correctly

  1. languages contains English and Japanese - languages is an array, again, and do you want to count all where either English or Japanese is present in the language array, or do you want both? THAT WASN’T CLEAR. So I was trying this for a while:

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

Some questions!!!

What is the diference between $in and $or comparision?

Check out the query operator $nor.

Read on the $and operator. Since you are being asked for English AND Japanese, you will need both of them.

Those were the ones I used, but the correct way is even easier, you will hit yourself on the head when you see the answer. You seem to grasp the logic, you just need to use the right queries, keep it up.


In addition see



I got the answer correctly. But I definitely need to go through the documentation for and, nor, all, nin - initially.