MongoDB order of operators -
i trying find movies which:
- contains "comedy" , "crime" in "genres".
- "comedy" listed first
i know query such:
.find({ "genres": ["comedy", "crime"] })
however, cannot grasp why following doesn't work:
.find({ "genres.0": "comedy", "genres": { $size: 2 }, "genres": { $all: ["comedy", "crime"] } }
as result, entries such as:
["comedy", "crime", "drama"]
but why?
you have genres
twice in find-object, means second entry overwrites first. when have 2 conditions same field, either need use $and operator or combine them this: "genres": { $size:2, $all: ["comedy", "crime"] }
Comments
Post a Comment