mongoengine
mongoengine copied to clipboard
Fields starting with underscore ignored on to_mongo or to_json call on DynamicDocument
Hello, community.
I just realize that any field I define starting with an underscore will NOT be included in the serialization process.
I did some testing and this comes from MongoEngine since if I use the Pymongo collection, I get every field.
Is this a defined behavior? I could not find anything in the documentation about it. Please let me know if I should create an example code.
Just tried in a terminal and it seems to be working ok, please provide a reproducible snippet
Okay, so it looks like it doesn't work for DynamicDocuments.
In [1]: from mongoengine import DynamicDocument
In [2]: class MyDynamicDoc(DynamicDocument):
...: pass
...:
In [3]: MyDynamicDoc(_a="a", b="b").save()
Out[3]: <MyDynamicDoc: MyDynamicDoc object>
In [4]: MyDynamicDoc.objects.to_json()
Out[4]: '[{"_id": {"$oid": "63184cac2a33214dee46cce7"}, "b": "b"}]'
I will update the title of the issue.