Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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)

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:

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...