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

103
Vistas
Update MongoDB field using value of another object array field from current document

I have this data:

{
    "_id" : ObjectId("5fe9b45d3613f35f9c7fe013"),
    "capitainSide" : "",
    "soldierSide" : "",
    "status" : "creation",
    "type" : "invitations",
    "invitedUsers" : [ObjectId("5fceb82c2917434bb8ef4966")],
    "members" : [ 
        {
            "_id" : ObjectId("5fb71aebc0f0ea402cd8e007"),
            "role" : "capitain",
            "side" : "black",
        }
    ]
}

and I want to get this result:

{
    "_id" : ObjectId("5fe9b45d3613f35f9c7fe013"),
    **"capitainSide" : "black"**
    **"soldierSide" : "white"**
    "status" : "creation",
    "type" : "invitations",
    "invitedUsers" : [ObjectId("5fceb82c2917434bb8ef4966")],
    "members" : [ 
        {
            "_id" : ObjectId("5fb71aebc0f0ea402cd8e007"),
            "role" : "capitain",
            "side" : "black",
        },
        {
            "_id" : ObjectId("5fb71aebc0f0ea402cd8e008"),
            "role" : "soldier",
            "side" : "white",
        }

    ]
}

Actually, I want to update 'capitainSide' field with the value of members array where the role = "capitainSide" in the value of 'side' field, and the same to 'soldierSide' field

about 4 years ago · Juan Pablo Isaza
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