Home > Software engineering >  How can I query multiple condition for a single Mongoose Model child in mongoose Model.find()?
How can I query multiple condition for a single Mongoose Model child in mongoose Model.find()?

Time:07-28

How can i use mongoose Model.Find() method to filter out my query for a multiple condition on a single Model Property. I used the below code only return the second query find condition, it return the pneumatic equipments only.

router.get('/Equipments',async  (req, res) =>{
try{
    const equipments = await Equipments.find({"EquipmentType" : "electrical" , "EquipmentType" : "pneumatic" })
    res.status(201).send(equipments)
}catch(e) {
    res.status(500)
} 

})

Is there an OR like operator for the condition?

CodePudding user response:

Use $or condition, like this

await Equipments.find({$or:[{"EquipmentType" : "electrical"},
                            {"EquipmentType" : "pneumatic"}]})
  • Related