Back to Skills

mongodb

Work with MongoDB databases using best practices. Use when designing schemas, writing queries, building aggregation pipelines, or optimizing performance. Triggers on MongoDB, Mongoose, NoSQL, aggregation pipeline, document database, MongoDB Atlas.

270stars60forksUpdated 8/16/2026

Security Assessment

Safe(95/100)
Security Score95/100

About mongodb

The mongodb skill is a best-practices reference for working with MongoDB and Mongoose in TypeScript/Node.js. It solves the problem of writing correct, secure, and performant document-database code by consolidating connection setup, schema design, queries, aggregation, and optimization patterns into a single guide with runnable code examples. It triggers on tasks involving MongoDB, Mongoose, NoSQL, aggregation pipelines, document databases, and MongoDB Atlas.

The guide covers native driver and Mongoose connection setup (with connection pooling, timeouts, connection-event handling, and graceful SIGINT shutdown), schema design (validation, indexes including text indexes, embedded documents versus references and when to use each, populate and nested populate, and virtuals for computed and reverse-reference fields), and a broad set of query operations (filters, the query builder, comparison/logical/element/array operators, text search, regex, and lean queries for speed). It demonstrates update operations and operators such as $set, $unset, $inc, and $mul. Security-conscious defaults appear throughout, for example marking password fields as select:false so they are never returned by default and stripping password and version fields in the toJSON transform.

It targets backend and full-stack JavaScript/TypeScript developers designing schemas, writing queries, building aggregation pipelines, or tuning performance. The connection string is read from an environment variable (process.env.MONGODB_URI), following standard credential practice, and all examples are ordinary application code with no destructive or exfiltrating behavior.

FAQ

What does it cover?

MongoDB native driver and Mongoose setup, schema design with validation and indexes, embed-versus-reference decisions, populate/virtuals, query and update operators, text search, aggregation, and performance tips like lean queries.

What language and libraries does it assume?

TypeScript/Node.js with the official mongodb driver and mongoose (installed via npm install mongodb mongoose).

Does it follow secure defaults?

Yes. Examples read the connection string from process.env.MONGODB_URI, mark password fields select:false so they aren't returned by default, and strip password and internal fields in the toJSON transform.

When should I embed versus reference documents?

It advises embedding when data is read together and doesn't grow unbounded, and referencing when data is large, shared, or changes independently, with populate examples for resolving references.

Install mongodb

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill