Chapter 1: Basic Aggregation - $match and $project - mistake?

Task:

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

My query:

{
  "imdb.rating": {$gte : 7},
  "genres" : { $nin: ["Crime", "Horror"]},
  "rated" : { $in: ["PG", "G"]},
  "languages" : { $in: ["English", "Japanese"]},
}

Did I make a mistake in the query? I have 877 movies found, not 23.

Hello @Eugene_Bos

t would be helpful for others to read and respond to your question if you could apply the proper formatting to your post. Before & after: code fencing (```) will make your post much more readable and answers more likely.
You may want to review the Getting Started guide from which has some great additional tips and information.

Concerning your question:
you are close, have a look at the following example where an OR condition is part of the $match

db.articles.aggregate( [
  { $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } },
  { $group: { _id: null, count: { $sum: 1 } } }
] );

also have an eye on your “languages” filter where you use $in

Regards,
Michael

3 Likes

Thanks a lot, they got me with “and” instead of “or” :frowning:

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