{"success":true,"name":"validate-at-the-mongodb-boundary-schemaless-is-not-ruleless","description":"Inserting data into MongoDB without any schema validation in place","category":"ai-brimind","path":"ai-brimind/validate-at-the-mongodb-boundary-schemaless-is-not-ruleless/SKILL.md","file":"SKILL.md","content":"---\nname: validate-at-the-mongodb-boundary-schemaless-is-not-ruleless\ndescription: \"Inserting data into MongoDB without any schema validation in place\"\n---\n\n# Validate at the MongoDB Boundary — Schemaless Is Not Ruleless\n\n## When to use\nProject uses MongoDB, and documents are being written without Mongoose schemas or JSON Schema validation on the collection.\n\n## Example request\nSaving whatever the API receives → one bad client writes price as a string; every later query breaks silently. 'MongoDB is schemaless so no validation needed' → schemaless means flexible storage, not 'no rules'; the app still assumes shapes. Using Mongoose but with type: Mixed everywhere → that disables the protection Mongoose exists to give. Direct driver inserts in a script bypassing Mongoose → collection-level JSON Schema validation catches what app code skips. Each maps to 'the database accepts anything, so YOUR boundary must not'.\n\n## Instructions\nAct as a gatekeeper who assumes every document written without validation will eventually be malformed. Before accepting insert/update code on MongoDB: (1) identify the write boundary — Mongoose model, API handler, or raw driver call, (2) ensure a real schema guards it: Mongoose schemas with proper types, required, enum, min/max — not Mixed as an escape hatch — or collection-level $jsonSchema validation if writes bypass Mongoose (scripts, other services), (3) remember NoSQL's flexibility is for EVOLVING shapes on purpose, not for accidental garbage: every field the app reads later is an implicit contract, so make it explicit now. Check what validation the stack already provides (Mongoose does casting and validation for free) before writing manual checks. If the intended document shape is not defined anywhere, define it or ask — do not infer it from one example payload. Only allow the write path once validation is confirmed at the boundary, and explain why bad data is now rejected at entry instead of discovered in production queries.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1048\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}