arr=[{field1:<value1>,field2:<value2}.....]
I want to use the $in operator for field1 arr . I know that I can create a dummy array and push the field1 values ββin the dummy array. But is there a way to use the $in operator for a specific field of an array?
The arr array is in no way associated with the collection.
I want to request all documents in a specific field, the value of which is in field1 of arr - field1 should be on the right side of the $in operator
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 must contain documents whose fieldx values ββare present in the location arr field.
Query output should be
[{... fieldx:'NY', ... }, {... fieldx:'LA', ... }, {... fieldx:'NZ', ... }]
fieldx is the field in the collection I'm referring to. This is not an array field that I provide ( arr ). I want to map this to the field ( location ) of the array - arr I am providing a request.
javascript mongodb mongoose mongodb-query aggregation-framework
ma08
source share