{"success":true,"name":"scope-every-mongodb-updatemany-deletemany-before-running-it","description":"About to run an update or delete that touches many MongoDB documents","category":"ai-brimind","path":"ai-brimind/scope-every-mongodb-updatemany-deletemany-before-running-it/SKILL.md","file":"SKILL.md","content":"---\nname: scope-every-mongodb-updatemany-deletemany-before-running-it\ndescription: \"About to run an update or delete that touches many MongoDB documents\"\n---\n\n# Scope Every MongoDB updateMany/deleteMany Before Running It\n\n## When to use\nProject uses MongoDB, and you are about to execute updateMany, deleteMany, or a migration script on real data.\n\n## Example request\ndeleteMany with a slightly wrong filter → an empty filter {} matches EVERYTHING; the collection is gone. Running the update before counting → countDocuments(filter) first tells you if 50 or 50,000 docs will change. Migration script with no dry-run → log the matched ids first, write second. No backup before a destructive script → mongodump of the collection takes a minute and makes the mistake recoverable. Each maps to 'measure the blast radius before pulling the trigger'.\n\n## Instructions\nAct as an operator who assumes every mass write against MongoDB will hit more documents than intended until proven otherwise. Before running updateMany, deleteMany, or any migration: (1) run countDocuments with the exact same filter and state the number out loud — if it surprises you, stop, (2) sample the matches (find(filter).limit(5)) and confirm they are the documents you meant, (3) check the filter for the classic traps: an accidentally empty {} filter, a typo'd field name that matches nothing or everything, a string-vs-ObjectId mismatch, (4) for destructive or irreversible changes, take a backup first (mongodump of the collection, or copy matched docs to a backup collection) and prefer a two-step approach: mark documents first, delete marked ones after review, (5) run migrations on a data copy before production when possible. Never combine 'writing the filter' and 'executing it' in one impulsive step. Only execute once the count, the sample, and the recovery path are confirmed, and explain what the verified blast radius is and how a mistake would be undone.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1142\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}