Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

383
Vistas
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

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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]
            }
        } }
    ]
);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda