0

I'm trying for the first time to use mongo, and I choose mongoengine. After defining the Document structure if I try to change it (adding a field, removing a field, renaming ecc..) the reading operations still works, but any other operation on previously stored document fail since they're note compliant anymore with the document structure. Is there any way to manage this situation? should I only user Dynamic documents with Dictionaries instead of EmbeddedDocuments?

kappa
  • 1,559
  • 8
  • 19

1 Answers1

1

Using DynamicDocument or setting meta = {'strict': False} on your Document may help in some cases but the only proper solution to this is running a migration script.

I'd recommend doing this using pymongo but you could also do that from the mongo shell. Every time your model change in a way that is not compatible, you should run a migration on the existing data so that it fits the new model. Otherwise mongoengine will complain at some point (mongoengine contributor here)

bagerard
  • 5,681
  • 3
  • 24
  • 48
  • ok, that's what I imagined since I'm used to work with SQL databases. I was wondering if there was any best practice like "versioning" or other, due to the NoSQL nature of the db. – kappa Apr 02 '20 at 10:08