$match homework question

I’m stuck on the first homework that we need to do. I’ve created a $match query that returns 24. The hint says it should be 23.

Looking at the documents returned it looks like my expression for genre is lacking because this shows up:
“_id”:ObjectId(“573a13e7f29313caabdc8bb0”),
“title”:“Mr. Holmes”,
“genres”:[
“Crime”,
“Drama”,
“Mystery”
]

My expression for genre looks like this:

genres : {$elemMatch: {$ne : "Horror", $ne :"Crime"}}

Does anyone know what I’m doing wrong?

Well Horror is not in the array so $ne:Horror is true and then Drama and Mystery make $ne:Crime also true, so the whole expression is true.

Same problem here, but I 'm using $nin.
Now I’m definitely confused.

The operator $elemMatch returns true if one of the element matches the condition. Since “Drama” is $nin Horror or Crime then whole condition is true even in $nin is false for Crime.

use $nin: [array list]
I hope you will finds this useful

1 Like

Yes, I was able to find my way at the end. :slight_smile: