mongodb-netlify
Use when building Netlify Functions or full-stack apps that use MongoDB Atlas or MongoDB-compatible deployments. Covers connection reuse, pool settings, Stable API, query safety, and serverless operational patterns.
Works with
--- name: mongodb-netlify description: Use when building Netlify Functions or full-stack apps that use MongoDB Atlas or MongoDB-compatible deployments. Covers connection reuse, pool settings, Stable API, query safety, and serverless operational patterns. license: MIT --- # MongoDB Netlify Skill Use this skill when a Netlify app or API uses MongoDB, especially MongoDB Atlas with the Node.js driver inside Netlify Functions. ## Core goals - Reuse `MongoClient` instances safely across warm invocations. - Keep connection counts predictable in serverless workloads. - Validate all input before it reaches MongoDB queries or updates. - Keep reads and writes explicit, typed, and bounded. ## Recommended stack - Use the official `mongodb` Node.js driver unless the project already standardizes on an ODM such as Mongoose. - Prefer MongoDB Atlas for hosted deployments. - Use the Stable API options when connecting to Atlas to reduce breakage when Atlas upgrades server versions. ## Netlify-specific guidance - Create the `MongoClient` once at module scope and reuse it across warm invocations. - Keep pool sizes intentionally small for public APIs that may scale horizontally. - Store the URI in a Netlify runtime environment variable with Functions scope. - Align Atlas region and Netlify function region when latency matters. - Use `netlify-serverless` for execution-model choices and `netlify-database-security` for generic secret policy. ## Reference files ### [`references/connection.md`](references/connection.md) **MongoClient setup and pool sizing** — Module-scope `MongoClient` with Stable API options (`strict: true`, `deprecationErrors: true`), `requireEnv()` fail-fast pattern, pool sizing table for serverless (low-traffic / moderate / burst / background), typed collection access with `WithId<T>`, `ObjectId` parse error handling, rules for idempotent `connect()` calls. ### [`references/query-safety.md`](references/query-safety.md) **Injection prevention and safe queries** — MongoDB operator injection example (raw body as filter → bypass), field allowlisting for sort/filter with `Set` + type narrowing, safe `updateOne` via validated schema (never `$set: req.body`), projection to exclude sensitive fields, aggregation pipeline safety, `ObjectId.isValid()` guard, rules. ## External references - [MongoDB Node.js driver: choose a connection target](https://www.mongodb.com/docs/drivers/node/current/connect/connection-targets/) - [MongoDB Node.js driver: connection options](https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connection-options/) - [MongoDB Node.js driver: connection pools](https://www.mongodb.com/docs/drivers/node/v6.x/connect/connection-options/connection-pools/) - [Netlify environment variables and functions](https://docs.netlify.com/functions/environment-variables/)
More Database skills
prisma-mongodb-upgrade
prisma/skills
Decision and migration guide for Prisma ORM MongoDB projects on v6, which have no upgrade path to v7. Use when a MongoDB project asks about upgrading Prisma, when "upgrade to prisma 7" comes up in a project with provider = "mongodb", or when evaluating a move to Prisma Next. Triggers on "upgrade prisma mongodb", "prisma 7 mongodb", "mongodb prisma migration", "prisma next mongodb".
azure-upgrade
microsoft/azure-skills
Assess and upgrade Azure workloads between plans, tiers, or SKUs, or modernize Azure SDK dependencies in source code. WHEN: upgrade Consumption to Flex Consumption, upgrade Azure Functions plan, change hosting plan, function app SKU, migrate App Service to Container Apps, modernize legacy Azure Java SDKs (com.microsoft.azure to com.azure), migrate Azure Cache for Redis (ACR/ACRE) to Azure Managed Redis (AMR).
azure-cost-optimization
microsoft/azure-skills
Identify Azure cost savings from usage and spending data. USE FOR: optimize Azure costs, reduce Azure spending/expenses, analyze Azure costs, find cost savings, generate cost optimization report, identify orphaned resources to delete, rightsize VMs, reduce waste, optimize Redis costs, optimize storage costs, AKS cost analysis add-on, namespace cost, cost spike, anomaly, budget alert, AKS cost visibility. DO NOT USE FOR: deploying resources (use azure-deploy), general Azure diagnostics (use azure-diagnostics), security issues (use azure-security)

