Example: Mongo db collection:
[
{
"user_id": 1,
"lead_id": 901,
...
...
},
{
"user_id": 2,
"lead_id": 902,
...
...
},
{
"user_id": 2,
"lead_id": 903,
...
...
},
{
"user_id": 3,
"lead_id": 999,
...
...
},
]
I have an array of objects:
const reqArr = [
{
"user_id": 1,
"lead_id": 901,
},
{
"user_id": 2,
"lead_id": 999,
}
]
I want to query the DB based on both user_id
and lead_id
present in each object in the array reqArr
. something like this or with aggregate pipeline
Model.find(reqArr)
My desired output would be something like this:
[{
"user_id": 1,
"lead_id": 901,
...
...
}]
I only know how to query based on the array of one field like Model.find({_id: {"$in": [array of ids ]}})
but not with more than one field in an array of object.
Any idea or workaround to achieve something like the above output or negation of the above output? I only need which objects in reqArr
are present in db collection or which are not. Thank you.