24 elements found instead of 23 chapter1 lab1

Hi everyone,
i’m attending the M121 course and i’m stuck in the Lab1 where my aggregation returns 24 documents instead of 23 as the teacher suggests.
I also check all the documents that my aggregation returns but it seems all good.
Can anyone help me to find where i’m wrong?
This is my aggregation:

db.movies.aggregate([{
			$match:{
				"imdb.rating":{$gte:7},
				$or: [ {genres:{$ne:"Crime"}}, {genres:{$ne:"Horror"}}],
				$or: [ {rated: {$eq:"PG"}}, {rated: {$eq:"G"}}],
				$and: [ {languages:{$eq:"English"}}, {languages:{$eq:"Japanese"}}]
				}},
		      {
			     $project:{_id:0, "imdb.rating":1, genres:1, rated:1, languages:1}	

		      }])

Thanks in advance!

Hi @Luciano_Bigiotti, welcome to the community.
Seems like you are already halfway there, but seems like you have missed some key underlying concerns for genres and languages.
I would recommend you to learn about $all and $nin operator to enhance your query.

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi @SourabhBagrecha,
thank you for your answer and apologize if i didn’t reply earlier.
I folllow your suggestion and everything went well.
I have other question:

  1. Writing
    $and: [ {languages:{$eq:“English”}}, {languages:{$eq:“Japanese”}}]
    is equal to use $all , am i right?
    In fact i select all the documents that have in the array English and Japanese. Obvously there could be also other langueges (Spanish, French etc) but there must be English and Japanese at the same time.

  2. The only weak point in the previous point is using $or instead of $and. Like in
    $or: [ {genres:{$ne:“Crime”}}, {genres:{$ne:“Horror”}}]
    right?

Thanks in advance for your answer
Regards

Since a query is a JSON document, you cannot have 2 fields with the same key. The last occurrence will override the previous ones.

This means the query

is equivalent to

{ '$match': 
   { 'imdb.rating': { '$gte': 7 },
     '$or': [ { rated: { '$eq': 'PG' } }, { rated: { '$eq': 'G' } } ],
     '$and': 
      [ { languages: { '$eq': 'English' } },
        { languages: { '$eq': 'Japanese' } } ] } }

You lost the $or: [ {genres:{$ne:"Crime"}}, {genres:{$ne:"Horror"}}] in the process.