arr=[{field1:<value1>,field2:<value2}.....]
I want to use the $in operator against the field1 of arr. I know I could create a dummy array and push the field1 values in the dummy array. But is there a way to use the $in operator against a particular field of an array?
The arr array is no way related to the collection.
I want to query all the documents on a particular field whose value is in the field1 of arr - field1 should be in the right hand side of operator $in
Example:
arr=[{name:'foo',location:'NY'},{name:'bar',location:'LA'},{name:'foobar',location:'NZ'}]
db.collection.find({fieldx:<Here I want some method to obtain all documents whose fieldx values are in the location field of arr>})
The output should contain documents whose fieldx values are present in the location field of arr.
The ouput of the query should be
[{...
fieldx:'NY',
...
},
{...
fieldx:'LA',
...
},
{...
fieldx:'NZ',
...
}]
fieldx is the field in the collection I am querying on. It is not a field of the array I'm providing(arr). I want to match this to a field(location) of array - arr I'm providing the query.