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

294
Vistas
MongoDB: Remove attribute from nested Object Array

I have to remove an attribute from an deep nested object inside an array of objects.
It looks like this:
Array

I want to unset the IndividualAge only for one specific Period Type Past
for one specific Block with the name "HouseKeepingDamageCost", if it exists.
I have to take care, because the other Objects inside Blocks and
other Periods have also an attribute called "IndividualAge", they can stay.
Can someone help me ? I tried it with $elemMatch without success.

Thanks in advance.

Playgorund with my Data & Query: Mongoplayground

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

0

You want to use arrayfilters to do so:

db.collection.update({},
{
  "$unset": {
    "Blocks.$[block].Periods.$[period].IndividualAge": ""
  }
},
{
  "multi": false,
  arrayFilters: [
    {
      "block.Name": "HouseKeepingDamageCost"
    },
    {
      "period.Type": "Past"
    }
  ]
})

Mongo Playground

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