Reputation: 468
I would like to check if a field exist in pipeline aggregate
(existeTransformacion
) . If this field exist must be true to pass ($match
) and if is false I need to exclude from my results, but if not exist must be pass. How can I achieve this?
{
//...more data
"ubicacionActual": {
"transformacion": {
"trabajando": true,
}
},
//This field come from $project in this way
//$project: {existeTransformacion: '$ubicacionActual.transformacion.trabajando'}
"existeTransformacion": true,
"paso": 1
},
So basically:
If exist existeTransformacion
and existeTransformacion===true
must be showing.
If exist existeTransformacion
and existeTransformacion===false
must be not showing.
Upvotes: 1
Views: 107
Reputation: 13103
You need to use $or
and $exists
operators
{
$match: {
$or: [
{
"existeTransformacion": true
},
{
"existeTransformacion": {
$exists: false
}
}
]
}
}
Upvotes: 1