Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)
I just want to know that on what order each document follows in MongoDB collection?

1 Answer

0 votes
by (108k points)
edited by

The $natural argument returns items according to their natural order within the database. This natural ordering is considered to be an internal implementation feature in MongoDB. It reflects the insertion order with the following exception for the MMAPv1 storage engine. If you want "sorted" then you should perform an explicit "sort":

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

Or if you want a "natural" sort means in the order stored on disk:

Learn about full stack web development by signing up for this professional Full Stack Training offered by Intellipaat..

db.collection.find().sort({ "$natural": 1 })

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

Browse Categories

...