{"success":true,"name":"store-files-outside-mongodb-documents-hold-metadata-not-bina","description":"About to save uploaded files or images into MongoDB documents","category":"ai-brimind","path":"ai-brimind/store-files-outside-mongodb-documents-hold-metadata-not-bina/SKILL.md","file":"SKILL.md","content":"---\nname: store-files-outside-mongodb-documents-hold-metadata-not-bina\ndescription: \"About to save uploaded files or images into MongoDB documents\"\n---\n\n# Store Files Outside MongoDB — Documents Hold Metadata, Not Binaries\n\n## When to use\nProject uses MongoDB, and uploads (images, PDFs, media) are about to be stored as base64 or Buffer fields in documents.\n\n## Example request\nBase64 image inside a user document → the doc balloons, every read of the user drags the image along; store a URL/key instead. Files on object storage (S3-style), metadata in MongoDB → the standard pattern: the document holds filename, size, mime, and the storage key. Many small files, no object storage available → GridFS is MongoDB's built-in for files over 16MB or streaming; it exists so you don't invent chunking. Serving images from the database on every page view → the database becomes a file server; CDNs and object storage are built for that job. Each maps to 'databases index and query; file bytes belong in storage built for bytes'.\n\n## Instructions\nAct as an architect who separates two jobs the moment uploads appear: storing bytes, and storing facts about the bytes. When file storage intersects MongoDB: (1) default to the standard division — file bytes go to object storage (S3, GCS, or the platform's equivalent) or the filesystem/CDN, while the MongoDB document stores metadata: original name, mime type, size, upload date, owner, and the storage key/URL, (2) reject base64-in-document as a design: it bloats documents toward the 16MB cap, inflates every read that touches the doc, wrecks cache and index efficiency, and makes backups enormous — a document should stay small enough to move cheaply, (3) if requirements genuinely force files into MongoDB (no external storage allowed, need for replication with the data), use GridFS — the built-in chunked file mechanism — rather than hand-rolled Buffer splitting, and say why external storage was ruled out, (4) plan lifecycle: deleting the document should delete or orphan-track the stored file, so decide the cleanup path now. If storage constraints are unknown, ask before the first upload endpoint. Only implement once bytes and metadata have separate confirmed homes, and explain why reads, backups, and scaling all stay healthy as uploads accumulate.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1154\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}