DEV Community

Cover image for mongodb operators
Dezina
Dezina

Posted on

3 3

mongodb operators

$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)
Enter fullscreen mode Exit fullscreen mode

$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
      };
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay