MongoDB does not "order" documents at all unless you ask for it.
The main insert will create an ObjectId in the primary key _id , unless you tell it otherwise. This ObjectId value is a special value with "monotonic" or "constantly increasing" properties, which means that every value created is guaranteed to be greater than the last.
If you want to sort, do an explicit sort:
db.collection.find().sort({ "_id": 1 })
Or "natural" sort in the order stored on disk:
db.collection.find().sort({ "$natural": 1 })
This is largely a standard, unless otherwise indicated, or a query criterion that determines the sort order, selects the "index". But you can use this to โforceโ this order if the query criteria selected an index that was otherwise sorted.
MongoDB documents "move" during growing, so the _id order _id not always explicitly the same order as when receiving documents.
source share