0

I'm developing a e-commerce platform using mongodb, as the timestamp is a a part of mongodb's auto generated id, I expect I don't have to get the items using sort or order by.

But that wasn't the case, I've done the insert and update part, so the order of the item is not consistent now. The later created item appear in the middle. Why does that happened?

Community
  • 1
  • 1
Jennifer
  • 905
  • 9
  • 20

1 Answers1

1

You should not rely on internal ID calculation — its only purpose is to be unique, not sequential.

Common pattern in cases such as yours is to add a field time in your item, then createIndex() on the collection and sort items whenever you get them using find().

zlumer
  • 6,844
  • 1
  • 25
  • 25