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, andemailare stored in individual fields.homePhone、cellPhone和email)存储在单独的字段中。Over time, fewer customers have随着时间的推移,拥有homePhonenumbers, so the company modifies the schema to move contact information to a genericcontactsdocument, which has variable subfields.homePhone号码的客户越来越少,因此公司修改了模式,将联系人信息移动到具有可变子字段的通用contacts文档中。After the schema change, the company implements the Schema Versioning pattern, and adds a模式更改后,公司实现了Schema Versioning模式,并添加了一个schemaVersionfield to tell the application how it should query each document.schemaVersion字段来告诉应用程序应该如何查询每个文档。
Tasks任务
To learn how to keep a history of document and schema changes, see these pages:要了解如何保存文档和模式更改的历史记录,请参阅以下页面: