$in
The $in operator selects the documents where the value of a field equals any value in the specified array.
jobIds [
{ _id: 61d3e5dc0b2613ae328cc0c5 },
{ _id: 61d3e66e0b2613ae328cc0c6 },
{ _id: 61d3e74a0b2613ae328cc0c7 },
{ _id: 61d556dc0b2613ae328cc169 },
{ _id: 61d57dc20b2613ae328cc16a },
{ _id: 61d580900b2613ae328cc16c },
{ _id: 61d59a9d0b2613ae328cc16d },
{ _id: 61d84bd90b2613ae328cc18f },
{ _id: 61d84c700b2613ae328cc190 },
{ _id: 61d92c710b2613ae328cc1ac },
{ _id: 61d92ecd0b2613ae328cc1ad },
{ _id: 61d947510b2613ae328cc1ae },
{ _id: 61d996ef0595f55e1f4e0a40 }
]
const mongoIds = jobIds.map(id => id._id)
console.log("mongoIds", mongoIds)
const result = await Slot.find({jobId: { $in:mongoIds }})
console.log("result", result)
$exists
we can check the existence of the field in the specified collection using the $exists operator & setting it true
const queryObject = {
jobId: { $in:objectIds },
candidateId: {$exists: true},
excluded: false
};
Top comments (0)