MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How do you handle schema versioning in MongoDB without downtime?
senior LevelDatabases & SQL
In Simple Words: Use the Schema Versioning Pattern:
- Include a
schemaVersion: 2attribute on every document. - In your application domain layer, write an adapter that accepts old versions and dynamically transforms them in memory to the modern structure.
- When an old document is updated, the app saves it with the newest schema version.