mongodb’s db.find().limit(1000) does NOT return the first 1000 documents I inserted. How would I make mongodb return documents in the order they were inserted?
How were they inserted? Basically you’ll need to sort them before adding a limit, either on the _id or another field that was added when the documents were added.
_id sorting should be sufficient but if there are multiple clients adding documents at the same time and clocks are slightly out of sync then there could be an edgecase where this does 100% return them in the order they were actually inserted.
This is as the mongodb driver may have generated the ID using the local machine clock as opposed to being server generated.
What’s the usecase for this?