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

498
Views
Usando $existe en MongoDB $cond

Para el fondo, tengo que crear un campo en una colección, pero SOLO si otro campo conocido (una matriz) no está vacío. Estoy tratando de hacer un filtro booleano con $ y algunas condiciones:

 $set: { clientsAllowed: { $cond: { if: { $and: [ { businessAllowed: { $exists: true }, }, { businessAllowed: { $type: "array" }, }, { businessAllowed: { $ne: [] }, }, ], }, then: [...], else: [...], }, } }

Pero me sale este error:

$conjunto no válido :: causado por :: Expresión no reconocida '$existe'

¿El $exists mal formateado? ¿O es el escenario $and ? ¿Algunas ideas?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Escriba cond para businessAllowed es suficiente. No es necesario comprobar si existe o no.

 db.collection.aggregate([ { $set: { clientsAllowed: { $cond: { if: { $and: [ { "$eq": [ { $type: "$businessAllowed" }, "array" ] }, { $ne: [ "$businessAllowed", [] ] } ] }, then: [], else: [] } } } } ])

parque infantil mongo

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!