Lab1: $match Home Work Assignment

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”

Solution ::

You are really unclear on the concept:

@ Santosh_97355

I have edited your post to conform to our community guidelines. Please adhere to these in the future. Thanks.

1 Like

MongoDB shell version v4.0.5
connecting to: mongodb://,,
2019-01-13T16:34:55.016-0500 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/,,
2019-01-13T16:34:55.326-0500 I NETWORK [js] Successfully connected to (1 connections now open to with a 5 second timeout)
2019-01-13T16:34:55.333-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to (1 connections now open to with a 5 second timeout)
2019-01-13T16:34:55.699-0500 I NETWORK [js] Successfully connected to (1 connections now open to with a 5 second timeout)
Implicit session: session { “id” : UUID(“b4235ded-5afa-4370-8295-f2057f19f5cd”) }
MongoDB server version: 3.6.9
WARNING: shell and server versions do not match

I use 4.0.5 shell and getting a different result for count $match. I got 9 for find and 8 for $match. Is it a known issue?


MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.solarSystem.count();
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.solarSystem.aggregate([{
… “$match”: { “type”: { “$ne”: “Star”} }
… }, {
… “$count”: “planets”
… }]);
{ “planets” : 8 }

I guess that there is something (1 document) that is a ‘Star’. That’s why you get 8 planets. I would try to match with type $eq Star to see what is happening.

@ Arivoli_48247

Well, the result makes perfect sense, doesn’t it? The solar system consists of 1 Star (the Sun) and 8 (as of now :wink: ) planets. So there are 9 documents in the collection, of which 8 are not “Star”.

Also, I would strongly recommend that you create new posts for new topics rather than simply tacking a new question onto a old post. Although the new Discussion Forums are better than the old ones at handling this, I might well have missed this if @ steevej-1495 hadn’t replied. Just FYI.


Please, I cannot find neither the rated field nor the languages field and so I do NOT know how to write include them in my $match query.

I ran the db.movies.findOne(). I sure can see other fields (imdb.rating, genres) expect the rated and langauges field. I them limited my find to 3 documents using db.movies.find({}).limit(3).pretty(). Still couldn’t find said fields.

Please, help asap.

Sorry for the bother.

I simply had to search for documents that contained the rated and languages field.

I’m good now, thanks.

Kind regards.


Please go through the movie collection once again, there are around 44497 number of documents but you have checked only three documents.
Go through the collection again in compass use $exists opperator and start build your query.