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

325
Vistas
How to convert structure of mongo db document's object

I have a document with the following structure:

id:  6229d3fd40bac327243e4ww2
userID: "594e710c-c632-3ae-929a-f13e294ee6ef"
appID: "622994e2b98225609b89affd"
notifications:Object
     6229d3e040bac3272qwe4441: 1  
     622ew3e041bac3272qwe4441: 1

I want to update this structure to this:

id:  6229d3fd40bac327243e4ww2
userID: "594e710c-c632-43ae-929a-f13e294ee6ef"
appID: "622994e2b98225609b89affd"
notifications:Object
     6229d3e040bac3272qwe4441: {a:1, b:false}  
     622ew3e040bac3272qwe4441: {a:1, b:false}

I am having trouble with iterating the notification objects fields as its is random hex string. I have tried using following solutions but not able to get the expected result MongoDB Aggregation pipeline: use of For loop

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

0

db.collection.update({},
[
  {
    $set: {
      notifications: {
        $arrayToObject: {
          $map: {
            input: { $objectToArray: "$notifications" },
            as: "n",
            in: {
              k: "$$n.k",
              v: { a: "$$n.v", b: false }
            }
          }
        }
      }
    }
  }
],
{
  multi: true
})

mongoplayground

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