Match query gives 9 results in Lab - $match assigment of chapter 1

Hey, I am using the same provided through the course, but I am getting a different results.

Hi @harsh_44041,

Please check your discourse inbox and let me know if you have any questions.


Hi Sonali, I to have reached this answer. How do I contact you to send code? I feel I am very close.

Hi @Steve_33394,

You can check your discourse inbox and reply there with your query.

Please feel free to reach out if you have any questions.


i’m sorry but what/where is the “discourse inbox”?

It will be like
Replace your_id with your mongodb university id

1 Like

Hi @Steve_33394,

When you are logged into discourse, you should see your icon on the right-hand top corner:

Click on the icon and select the message option as shown in the screenshot below:
Screenshot 2020-07-28 at 7.10.30 PM

You will be able to see the discourse inbox messages that you received.

Please feel free to reach out if you have any questions.


So, I’m going through this Aggregation M121 and hit this snag as well?
ie. Chapter 1: Basic Aggregation - $match and $project

Lab - $match

I realize I’m pretty slow but I’ve spent hour on this trying to find the 23 results but keep getting 9. I modified validateLab1.js from 23 to 9 but it doesn’t return an answer that’s an option for the quiz (19).

Nonetheless, I get it…I’m new and it’s all very syntactically “challenging” but I GOTTA know!!!

What am I missing to get to 23?

… [
… {$match:{$or:[{rated:“PG”},{rated:“G”}]}},
… {$match:{$nor:[{genres:“Crime”},{genres:“Horrror”}]}},
… {$match:{$and:[{languages:[“English”,“Japanese”]}]}},
… {$match:{“imdb.rating”:{$gte:7}}},
… {$project:{“title”:1,“rated”:1,“genres”:1,“languages”:1,“imdb.rating”:1,"_id":0}},
… {$count:“recs”}
… ]
… )
{ “recs” : 9 }

Thanks in advance!!

Well, I managed to hack my way to 23. Seems I’m not understanding how the $and works for my aggregator.
I ended up swapping:


1 Like

First, you have to know that:

is logically equivalent to:


See for more details.


is equivalent to

rated : { $in: [ "PG" , "G"] }


You got 9 rather that 23 with $and:[{languages:[“English”,“Japanese”]}] because the expression languages:[“English”,“Japanese”] matches only arrays with exactly the 2 elements in the same order. So document having languages : [ “Japanese”, “English” ] won’t match. Documents with ***languages : [ “English” , “Japanese” , “French” ] will also not match. See for more details.

As a debug tip when a count does not match the expected result, remove the $count stage and look at the data. Compass is really nice to investigate issues like than as it is easy to remove a stage and analyse the schema for the selected documents.

1 Like

Hi @Colin_Poon_Tip,

In addition to Steeve’s response,

I would recommend you to refer MongoDB documentation extensively for any stage or operator that you encounter in the course.
This will help you understand the usage correctly and practice enough to master MongoDB Aggregation!!

Please feel free to reach out if you have any questions.

Kind Regards,

1 Like