Mongodb compass error

{“actors”:[“Henry Fonda”,“Jason Robards”]}
this query is not working in filters.
if i try with square brackets it shows nothing in the output.

I’m assuming this query is being run on the movieDetails collection.

If you’re trying to find all documents with either of the actor names in it then use $in like this:

{“actors”: {"$in": [“Henry Fonda”, “Jason Robards”]}}

Now, if you’re looking to find documents with both of them as actors then this might help:

{“actors”: {"$all": [“Henry Fonda”, “Jason Robards”]}}

$all operator checks for presence of all the items listed in array unlike $in which gives any results which has either of the elements present in them. Consider $all as AND operation and $in as OR operation.

I found $all by searching in the documentation as it is not being taught in the basics course atleast upto chapter 3 which I haven’t started yet.

1 Like