Reputation: 17548
If I add items to a ListField on a mongo db document in a specific order and then write it to the database, is it guaranteed that all subsequent reads will see the list in the same order?
e.g. write
obj = MyDocument.by_id(id)
obj.list_field = []
obj.list_field.add("a");
obj.list_field.add("b");
obj.list_field.add("c");
obj.save()
read
obj = MyDocument.by_id(id)
for x in obj.list_field:
print(x)
# will it always print in this order?
# a
# b
# c
this is using python mongoengine ORM v0.4.2
Upvotes: 0
Views: 73
Reputation: 6364
Yes they do, the driver is faithful to the underlying data and mongoDb guarantees this (Do arrays stored in MongoDB keep their order?)
Upvotes: 1