Reputation: 375
if type is check box it should check with two condition one type is checkbox and status is completed or process it should return output. but if type is radio and status should be completed
How to combine or with $cond condition please guide
db.collection.find({
$and: [
{
$or: [
{
"type": "radio"
},
{
"type": "checkbox"
},
]
},
{
$cond: {
if: {
type: "checkbox"
},
then: {
$or: [
{
"status": "completed"
},
{
"status": "process"
}
]
},
else: {
"status": "completed"
}
}
}
]
})
https://mongoplayground.net/p/NM7Bp4SAsPl
Upvotes: 0
Views: 467
Reputation: 522626
Too overcomplicated. You want to match documents which:
In other words:
So:
{
$or: [
{ status: 'completed', type: { $in: ['checkbox', 'radio'] } },
{ status: 'process', type: 'checkbox' }
]
}
Upvotes: 2