Document and Schema Versioning
On this page
Your schema may need to change over time to account for changing technical requirements. When your schema changes, you can use schema design patterns to retain your original document structure. By retaining historical versions of documents and schemas, you avoid performance-intensive schema migrations and downtime.
Use Cases
Use versioning patterns when your data requirements change and you want to keep historical data in its original form. Versioning patterns are most useful when your application meets any of these conditions:
Application downtime is not an option for migration.
Updating documents to the new schema may take hours, days, or weeks to complete.
Updating documents to the new schema is not a requirement.
Versioning patterns help you decide how data migrations take place and provide more flexibility relative to tabular databases.
Consider these specific application use cases for versioning patterns:
An insurance company lets customers modify their policy to insure additional items. When a customer changes their policy, the insurance company keeps a record of the policy changes over time. The company uses the Document Versioning pattern to track policy revisions by storing each update in a separate document. Historical data is stored in a separate collection, and does not impact queries on current data.
A company stores customer contact information. In the original schema, various contact methods like
homePhone
,cellPhone
, andemail
are stored in individual fields. Over time, fewer customers havehomePhone
numbers, so the company modifies the schema to move contact information to a genericcontacts
document, which has variable subfields. After the schema change, the company implements the Schema Versioning pattern, and adds aschemaVersion
field to tell the application how it should query each document.
Tasks
To learn how to keep a history of document and schema changes, see these pages: