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

149
Vistas
findOne is gaving me the same result for different IDs

I have a list of different Ids , and I'm trying to find the products that have those Ids and push them in another array. The problem is that when I use findOne() return the same product for all Ids.

let  wishpro = ['632a5e5rtybdaafd23','65fdaartbdqip55'];
            
            for(let i = 0; i < wishpro.length ; i++) {
                let x = await product.findOne({id : wishpro[i]});
                console.log("x : " + x.id )
                wishProducts.push(x);
            }

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

0

findOne() will return the first match that it finds. Instead, you can use find() with $in operator, and fetch all of the records with one query:

const wishpro = ['632a5e5rtybdaafd23','65fdaartbdqip55'];

const result = await product.find({ id: { $in: wishpro } });
almost 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