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

166
Vistas
Is there a way to search for a value in mongodb in object with arrays, and the value could be present in any object of that array

This is the structure:

{"_id":"_vz1jtdsip",
"participants":{
   "blue":["finettix"]
    "red":["EQm"]
    },
"win":"red","
__v":0}

and i have many documents as this, I want to search in participants blue/red for a specific name and to return that document. For code I`m using javascript, I tried something like this:

await gamesSchema.find().where('participants.red').in(player[0].Nickname);

but this only return participants.red, I could make another call for blue but I would like them in the order as they are in database, so I`m asking if there is a method to search at once.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try an $or condition :

await gamesSchema
    .find({
        $or : [{
            "participants.red" : player[0].Nickname
        },{
            "participants.blue" : player[0].Nickname
        }]
    })
    .lean() // Returns simple JSON, not a collection of Mongoose objects
    .exec(); // Returns a true Promise, not a thenable. Good with await
about 4 years ago · Juan Pablo Isaza 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