Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!