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

83
Views
how to get last insert data to first insert data from mongodb

I am having a problem finding data from MongoDB. I am trying to get data last inset first to insert data. if you know how I can get data effortless please help me? below the MongoDB data, I want to show this data on my website last inset to first insert data. I hope so I will get my answer. thank you.

{ "_id" : ObjectId("5cefb17eef71edecf6a1f6a8"), "Name" : "John" }
{ "_id" : ObjectId("5cefb181ef71edecf6a1f6a9"), "Name" : "Chris" }
{ "_id" : ObjectId("5cefb185ef71edecf6a1f6aa"), "Name" : "Robert" }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To get your data sorted from the last inserted document you need to use sort() function.

db.collection.find({}).sort({_id:-1})

.sort({_id:-1}) sorts the data in a collection from Last to First inserted.

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!