Reputation: 505
I am trying to find movies which:
I know I could query as such:
.find({ "genres": ["Comedy", "Crime"] })
However, I cannot grasp why the following doesn't work:
.find({
"genres.0": "Comedy",
"genres": { $size: 2 },
"genres": { $all: ["Comedy", "Crime"] }
}
As a result, I get entries such as:
["Comedy", "Crime", "Drama"]
But why?
Upvotes: 0
Views: 51
Reputation: 69663
You have genres
twice in your find-object, which means the second entry overwrites the first. When you have two conditions for the same field, you either need to use the $and operator or combine them like this: "genres": { $size:2, $all: ["Comedy", "Crime"] }
Upvotes: 2