home / skills / partme-ai / full-stack-skills / mongodb

mongodb skill

/skills/mongodb

This skill helps you work with MongoDB by guiding document operations, queries, aggregation, indexes, and best practices for scalable data design.

npx playbooks add skill partme-ai/full-stack-skills --skill mongodb

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
664 B
---
name: mongodb
description: Provides comprehensive guidance for MongoDB database including document operations, queries, aggregation, indexes, and best practices. Use when the user asks about MongoDB, needs to work with MongoDB collections, write queries, or design MongoDB schemas.
license: Complete terms in LICENSE.txt
---

## When to use this skill

Use this skill whenever the user wants to:
- [待完善:根据具体工具添加使用场景]

## How to use this skill

[待完善:根据具体工具添加使用指南]

## Best Practices

[待完善:根据具体工具添加最佳实践]

## Keywords

[待完善:根据具体工具添加关键词]

Overview

This skill provides practical, hands-on guidance for working with MongoDB, covering document operations, queries, aggregation pipelines, index design, and schema modeling. It helps developers write efficient queries, design collections, and apply best practices for performance and scalability. Use it when you need actionable examples, troubleshooting tips, or recommendations for production-ready MongoDB usage.

How this skill works

The skill inspects the user's intent and returns concrete MongoDB examples, shell/driver commands, and design advice tailored to their problem. It can generate CRUD operations in the Mongo shell and common drivers (Python/PyMongo, Node.js), craft aggregation pipelines, suggest index strategies, and recommend schema patterns. For performance issues it analyzes query shape and suggests indexes or pipeline rewrites.

When to use it

  • Writing or optimizing queries and aggregation pipelines
  • Designing document schemas and collection relationships
  • Choosing and creating appropriate indexes for performance
  • Migrating data or modeling many-to-many/one-to-many relationships
  • Troubleshooting slow queries, replication, or sharding issues

Best practices

  • Model data based on query patterns: embed for locality, reference for large or shared data
  • Create indexes that match query filters and sort patterns; use compound indexes thoughtfully
  • Limit projection to needed fields to reduce network and memory overhead
  • Use aggregation pipeline stages in the order of selective filters first
  • Monitor usage with explain(), serverStatus, and MMS/Atlas monitoring for hotspots

Example use cases

  • Show a PyMongo example to insert, update, and query documents with pagination
  • Build an aggregation pipeline to group, filter, and compute metrics over time-series data
  • Recommend an index strategy for a query with multiple equality and sort conditions
  • Design a schema for a blog platform supporting comments, tags, and user profiles
  • Provide migration steps to convert embedded arrays into referenced collections for scale

FAQ

Should I embed or reference related data?

Embed when related data is frequently read together and stays reasonably sized; reference when data grows unbounded, is shared across documents, or requires separate lifecycle management.

How do I diagnose a slow query?

Run explain() for your query to see index usage and stage execution; check index coverage, use projection, and consider adding or adjusting compound indexes. Monitor CPU, I/O, and page faults for resource bottlenecks.