Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda