{"success":true,"name":"fix-mongodb-field-naming-drift-before-it-spreads","description":"Noticing the same concept named differently across MongoDB documents","category":"ai-brimind","path":"ai-brimind/fix-mongodb-field-naming-drift-before-it-spreads/SKILL.md","file":"SKILL.md","content":"---\nname: fix-mongodb-field-naming-drift-before-it-spreads\ndescription: \"Noticing the same concept named differently across MongoDB documents\"\n---\n\n# Fix MongoDB Field Naming Drift Before It Spreads\n\n## When to use\nProject uses MongoDB, and collections show inconsistent field names or shapes for the same concept (userId vs user_id vs owner).\n\n## Example request\nuserId in orders, user_id in comments, owner in files → every $lookup and every developer must remember three spellings; queries silently miss data. isActive boolean in some docs, status string in newer ones → two generations of schema coexisting undeclared; readers must handle both or bug. Fixing it by adding OR-conditions in queries → that entrenches the drift; the fix is one canonical name plus a migration. New collections copying whichever old collection was open → drift reproduces; a written naming convention stops the source. Each maps to 'schemaless lets drift happen silently — consistency must be maintained on purpose'.\n\n## Instructions\nAct as a codebase gardener who treats the second spelling of the same concept as the moment to act, because the third and fourth are coming. When field naming or shape drift appears in MongoDB collections: (1) inventory the variants honestly — query distinct field presence ($exists checks, aggregation on $objectToArray if needed) to see which spellings live in real data, not just in code, (2) declare ONE canonical name and shape, aligned with the project's convention (pick camelCase or snake_case once, write it down where schemas are defined), (3) fix in the correct order: update the write paths first so no new drift is born, then migrate existing documents ($rename in an updateMany is built for exactly this), then delete the compatibility reads — never leave permanent dual-name handling in queries, because that converts a data bug into architecture, (4) prevent recurrence with mechanism: Mongoose schemas or collection validators make the canonical name enforced instead of remembered. If renaming risks breaking external consumers (APIs, other services), map who reads the field before migrating and ask. Only close the issue once data, writes, and reads all speak one name, and explain why the concept now has exactly one spelling everywhere.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1157\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}