{"success":true,"name":"mongoose-can-t-see-inside-mixed-and-nested-paths-markmodifie","description":"Using Mongoose and a save() silently ignores changes to nested or Mixed fields","category":"ai-brimind","path":"ai-brimind/mongoose-can-t-see-inside-mixed-and-nested-paths-markmodifie/SKILL.md","file":"SKILL.md","content":"---\nname: mongoose-can-t-see-inside-mixed-and-nested-paths-markmodifie\ndescription: \"Using Mongoose and a save() silently ignores changes to nested or Mixed fields\"\n---\n\n# Mongoose Can't See Inside Mixed and Nested Paths: markModified or Set Whole Values\n\n## When to use\nProject uses Mongoose, and mutations to Mixed-type fields, nested objects, or array elements don't persist after save, with no error raised.\n\n## Example request\ndoc.settings.theme = 'dark' on a Mixed field, then save → nothing written, no error; invisible mutation. push into a plain-object structure inside Mixed → same silence; untracked change. date modified via its own methods (setHours) → the reference didn't change, Mongoose saw nothing; in-place blindness. — each changed contents Mongoose wasn't watching.\n\n## Instructions\nAct as a warehouse manager who knows the inventory system only logs pallets moving through the gate — rearranging boxes INSIDE a pallet is invisible to it. Mongoose tracks changes by watching assignments to schema-known paths; fields typed as Mixed (or untyped objects) are opaque pallets: mutate their insides and the document is 'unchanged' at save time, so the write is skipped silently — the cruelest kind of bug, succeeding in memory and lying to the database. Three escapes, in order of preference: define real schema paths instead of Mixed wherever the shape is actually known — typed paths are tracked automatically and validated too, per the schema-first principle; when Mixed is genuinely needed (free-form JSON), call markModified with the exact path after any internal mutation and before save — that is the official 'I rearranged inside this pallet' declaration; or sidestep tracking entirely by replacing the whole value with a new object (assignment of a fresh reference IS visible) — which also aligns with the no-mutation rules. Watch the sneaky variant: in-place mutations of Dates and array elements can dodge detection the same way. And know that atomic update queries (updateOne with operators) bypass this entire mechanism — but also bypass validation and hooks; choose per the project's rules. When a save 'works' but the data doesn't change, check what the document thinks changed (its modified-paths listing) before suspecting the database. Only proceed once every write to a Mixed or nested structure is either schema-typed, marked, or whole-value replaced.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #823\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}