I'm a little bit stuck with a query in mongodb and I think I am just looking for it wrong. What I am trying to do is run a query which returns all documents where a value for a specific field is somewhere in an Array.
It's not $in, because this checks an Array field for a specific value. I am trying to do the opposite. I want to do the operation on a String field and look inside an Array. I hope you understand what I mean, but I think it will become clear with an example.
Example:
{
hero: "The Flash",
name: "Barry Allen",
city: "Central City"
},
{
hero: "Green Arrow",
name: "Oliver Queen",
city: "Star City"
},
{
hero: "Batman",
name: "Bruce Wayne",
city: "Gotham City"
}
So assume I want all the heroes active in both Gotham City and Central City. I want do a query where city is in ["Gotham City", "Central City"].