arr=[{field1:,field2:
I want to use the $in
operator against the field1
of arr
. I
Extending Neil Lunn's answers, you can use map
function within query also.
var arr = [
{ "name": "foo", "location": "NY"},
{ "name": "bar", "location": "LA"},
{ "name": "foobar", "location": "NZ"}
];
db.collection.find({ "fieldx": { "$in": arr.map(function(x) { return x.location } ) } })
If you using ES6 syntax then
db.collection.find({ "fieldx": { "$in": arr.map(x => x.location ) } })