MongoDB SimplSchema ensure backwards compatibility while updating schema


Hi there, I am looking for some advice on best practices.

I have an existing schema on collections (app is running some time in production) where a field’s name is a) inconsistent with the naming conventions in my app an on top of that it is b) confusing (which is why I introduced some naming convention).

Changing this field’s name makes therefore sense in regards to development and clear communication between developers and avoid errors in upcoming methods by design.

However, if I just change the name of the field in the schema, it would crash my application at runtime of course, since the old documents still use the old schema.

My question now is (especially to those who dealt with such a case): How would you ensure, that the documents with the old schema will still be processable?

I thought about writing a shell script and going through all documents, replacing the fields one by one. This however requires off-time or at least I need to protect the data during this process. I am not sure here how to do in a safe manner.

They other way would be to introduce a wrapper that enables both field names. This option seems to be a bit odd to me since it bloats the code (imagine over 5 years 10 changes per year, introducing a new wrapper for each field change…).

Somebody here to share some experience on that?


Sounds like a job for