0

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

Alex Blex
  • 34,704
  • 7
  • 48
  • 75
James Wierzba
  • 16,176
  • 14
  • 79
  • 120

1 Answers1

1

Yes they do, the driver is faithful to the underlying data and mongoDb guarantees this (Do arrays stored in MongoDB keep their order?)

bagerard
  • 5,681
  • 3
  • 24
  • 48