Lab 1 Basic Aggregation pipeline error


I have got an error while creating a $match pipeline for the below question:

  • 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 have got the filtered records when i try this command:

db.movies.aggregate( [ {$match: {$nor: [ {genres: “Crime”}, {genres:“Horror”} ], $and: [ {languages:“English”}, {languages: “Japanese”} ] } } ] )
count: 533

but, when use the complete filter command my count is getting increased:

db.movies.aggregate( [ {$match: {$nor: [ {genres: “Crime”}, {genres:“Horror”} ], $and: [ {languages:“English”}, {languages: “Japanese”} ], { “imdb.rating” : {$gte:7} } } ] )

could anyone check and provide an update?

@ Suresh_58788

First of all, please do not post full code examples in the Forum – whether they work or not – as it can be confusing to other students.

Next, to debug your problem, start by using the find() operation rather than aggregate() to see what your results are. Use projection to simplify your results to just the key fields that you’re looking for. Also, I’d suggest taking the criteria given in the order shown (‘imdb.rating’, ‘genres’, ‘rated’ and ‘languages’) as I think that’s going to be the clearest way to see your issues – it is for me anyway (but that’s just a suggestion obviously :wink:)

Frankly, I see multiple errors in your $match that will need to be corrected before you can get the desired answer. Good luck.