0

I am using mongoDB to store excel dump, I upload variable size of excel some time 20 rows sometime 40k rows. Yesterday suddenly order of all documents shuffled with random order.

When I uploaded same excel files again mongoDB is giving the documents in same order as present in excel on retrieval, but for excels uploaded a week back order is shuffled.

Although using the sort on objectId I am able to retrieve document in original order but it take extra time to fetch documents with sort operation as compared to plain find query.

The only change happened on database server is "server restart", I am using NodeJs and native mongoDB driver (NodeJS) for uploading excel in mongoDB.

Akshay Naik
  • 669
  • 1
  • 6
  • 22
  • As we discussed in comments on an older question, if you want predictable ordering of results you need to specify a sort order on a unique field. The default `_id` index is both unique and required, so is a good candidate for returning your results in a consistent order. – Stennie Dec 09 '19 at 13:01
  • Indeed, but as I mentioned sorting incurs some additional time in fetching data, which was working properly previously. discussing different issue in comment seemed unfair so created a new question. – Akshay Naik Dec 10 '19 at 08:01

0 Answers0