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

108
Views
Is mongoose findOne guaranteed to return the latest inserted doc it finds?

I have the following in the database:

username: Murat1010
firstName: Murat
lastName: Paşa
city: İstanbul
createdAt: 2022-07-15T23:24:32.382+00:00

username: Ömer98
firstName: Ömer
lastName: Demir
city: İstanbul
createdAt: 2022-07-15T23:25:00.023+00:00


username: Yaser334
firstName: Yasser
lastName: Tayyar
city: İstanbul
createdAt: 2022-07-15T23:27:59.688+00:00

I have the following Mongoose code:

const newestMember = await Users.findOne({city: "İstanbul"})

Is newestMember guaranteed to return Murat's Doc? guaranteed to return the newest one? can I stick to findOne? If it's not correct, then how?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

No it's not guaranteed. Read here I would do:

const newestMember = await Users.findOne({city: "İstanbul"}).sort({createdAt: -1})
about 4 years ago · Santiago Gelvez 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!