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

179
Vistas
Mongodb positional operator is not working

When I am trying to update just "title", it is working fine, but if I am trying to update the nested object in the array, it is not working.

Data: Data

Working:

const restaurant = await Restaurant.update(
    {_id: '60e6828e4992a2979fa0ba3e'},
    {$set: {title: "Hello}},
  );

Not working:

const restaurant = await Restaurant.update(
    {_id: '60e6828e4992a2979fa0ba3e', 'grades.grade': 85},
    {$set: {'grades.$.grade': 0}},
  );
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Demo - https://mongoplayground.net/p/caFBz-lx8dQ

Use $[]

The filtered positional operator $[] identifies the array elements that match the arrayFilters conditions for an update operation

db.collection.update(
 {},
 { $set: { "grades.$[elem].grade": 0 }},
 { arrayFilters: [ {"elem.grade": 85 } ]}
)
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