{"success":true,"name":"version-and-migrate-mongodb-schemas-flexibility-needs-a-plan","description":"Changing a MongoDB document shape that existing data already uses","category":"ai-brimind","path":"ai-brimind/version-and-migrate-mongodb-schemas-flexibility-needs-a-plan/SKILL.md","file":"SKILL.md","content":"---\nname: version-and-migrate-mongodb-schemas-flexibility-needs-a-plan\ndescription: \"Changing a MongoDB document shape that existing data already uses\"\n---\n\n# Version and Migrate MongoDB Schemas — Flexibility Needs a Plan\n\n## When to use\nProject uses MongoDB, and you are renaming, restructuring, or retyping a field that older documents already contain.\n\n## Example request\nRenaming fullName to name in the schema only → old docs still have fullName; every read now sees undefined. Changing a string field to an object → code handling only the new shape crashes on old docs. Adding schemaVersion to documents → code can branch per version or lazily upgrade docs on read; a named pattern (schema versioning). Running one updateMany migration → clean cut, but must be scripted, tested on a copy, and reversible. Each maps to 'old documents do not update themselves — pick a migration strategy'.\n\n## Instructions\nAct as a migration planner who treats every schema change as two problems: the new shape, and all the documents that still have the old one. Before changing a field's name, type, or structure in MongoDB: (1) check whether existing documents carry the old shape (they always do unless the collection is empty — verify, don't assume), (2) choose a named strategy explicitly: eager migration (an updateMany/aggregation script run once, tested on a copy first) or lazy migration (add a schemaVersion field, upgrade documents on read, keep read-code tolerant of both shapes until done), (3) make the transition window explicit: which code handles which version, and when the old shape is officially dead, (4) never rely on 'Mongoose defaults will cover it' — defaults apply to new docs, not stored ones. If you cannot test the migration on a data copy, say so and reduce risk (backup, batch in chunks). Only apply the schema change once the strategy for OLD documents is confirmed, and explain how every document — past and future — ends up readable.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1054\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}