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

190
Vistas
Mongoose retrieving all the oject values

I'm trying to retrieve all of the object values from an mongoose schema for example:

{
 id: 553a75a7e4b092e5edad4bce,
 name: Jeff,
 name1: Ricky,
 name2: Lexi,
 name3: Eric
} I'm expecting Jeff Ricky Lexi Eric

I used the following:

{
    Name.find(function(err, s){
    if (err){
      console.log(err);
    }
    else{
      mongoose.connection.close();

      Object.values(s).forEach(val=>{

      console.log(val));
      });

    }
  });
}

But I got this instead:

{
 id: 553a75a7e4b092e5edad4bce,
 name: Jeff,
 name1: Ricky,
 name2: Lexi,
 name3: Eric
} 

Any solutions for this?

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

0

Mongoose find method is not returning a single object but an array of objects.

If you wany to display values from them you can try using nested loops. Something like this should work

{
    Name.find(function(err, s){
    if (err){
      console.log(err);
    }
    else{
      mongoose.connection.close();
      
      s.forEach(obj => {
        Object.values(obj).forEach(val=>{

        console.log(val));
        });
      });
    }
  });
}

Just keep in mind that you would display every property of all returned objects.

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