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

167
Views
Why does await model.find().sort() sorts elements but not the result array?
const products=await Product.find().sort("condition")

In the above snippet, Product is my mongoose model. The above snippet sorts the result according to the condition but the snippet below does not:

let products=await Product.find()
const results=products.sort("condition")

I am following the "Node.js Projects" by Coding Addict on Youtube where he says that this is because using await returns a list where we cannot use the mongoose.sort() function. So what I am trying to understand is why does the sort() function not work in the second snippet as I checked the types of the value returned in both snippets and it was Obj in both the cases.

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