Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!