odmantic
odmantic copied to clipboard
Preserve document fields ordering
Saving document not preserving fields ordering:
class A(Model):
b: int
a: int
a = A(b=1, a=2)
engine.save(a)
> mongo --eval "db.publisher.find({})"
{
"_id": ObjectId("636de7e8731f89ec756c538c"),
"a": 2,
"b": 1
},
The engine.save and engine.save_all methods are actually behaving as upsert operations. In other words, if the instance already exists it will be updated. Otherwise, the related document will be created in the database.
I guess this upsert=True
operation is responsible for this behavior?
I found it very inconvinient to see how schema of your document is changed due to fields ordering ... Any plans on changing this, or im missing something ?
Thanks for the suggestion.
I'm not sure this is related to upsert
maybe there is a simpler way to fix that.
I'll have a look.