Refactoring documents in a NoSQL database

I read about the benefits of using NoSQL-style for a document database, and one of my problems is how to cope with the "refactoring" of data if necessary.

Permeable example from a person who has never worked with NoSQL:

Suppose in MongoDB we have a document called User that has an embedded document called Address, and later we decided that the Address document should be moved to a new collection.

What are the possible ways to do this, given downtime, performance, etc.

+4
source share
1 answer

Changing the scheme is quite simple when you do not have a formally defined scheme - all you have to do is update your own code so that it can process both old and new documents, usually by including both old and new fields and moving data from the old to the new either when loading, or before saving, if necessary.

Since there will be no data version conflicts between the code and the database, there is no downtime and it is trivial to call the existing load / save code on all documents if you want to complete the migration and remove support for old documents.

Changing indexed properties is a bit more complicated, but still easier than making changes to the SQL schema.

+3
source

Source: https://habr.com/ru/post/1332205/


All Articles