'create field in mongodb by $gte and condition $cond
I need to create a field on based on a condition in collection called locales:
if a place has more than 10 tables ("mesas_es"=10) the new field should be true, if the place has less than 10 tables ("mesas_es"=9)the new field should be false, the name of the new field is inspeccionar so far this is what I have get
db.locales.update({$and: [{desc_barrio_local: "GUINDALERA"},{desc_distrito_local:"SALAMANCA"},{desc_ubicacion_terraza: "Acera"}]},{$set: {inspeccionar: {$cond: {if: {$gte: ["mesas_es", 10]}, then: true, else: false}}}},{multi:true})
so far I only get a nested array containing the conditions
inspeccionar: Object $cond: Object if : Object $gte : Array then : true else : false
Solution 1:[1]
You need to update the documents with the aggregation pipeline as follows:
db.locales.updateMany(
{
desc_barrio_local: "GUINDALERA",
desc_distrito_local:"SALAMANCA",
desc_ubicacion_terraza: "Acera",
},
[
{ $set: {
inspeccionar: {
$gte: ["$mesas_es", 10]
}
} }
]
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chridam |
