mongodb

GitHub

MongoDB专家技能,涵盖模式设计、查询编写、聚合管道构建、索引优化及部署管理。指导用户根据访问模式设计Schema,利用聚合框架处理复杂逻辑,并通过索引策略提升性能,避免常见陷阱。

crates/openfang-skills/bundled/mongodb/SKILL.md RightNow-AI/openfang

Trigger Scenarios

需要设计或优化MongoDB数据库结构 编写复杂的MongoDB查询或聚合管道 进行MongoDB索引策略分析与性能调优 解决MongoDB部署与运维相关问题

Install

npx skills add RightNow-AI/openfang --skill mongodb -g -y
More Options

Non-standard path

npx skills add https://github.com/RightNow-AI/openfang/tree/main/crates/openfang-skills/bundled/mongodb -g -y

Use without installing

npx skills use RightNow-AI/openfang@mongodb

指定 Agent (Claude Code)

npx skills add RightNow-AI/openfang --skill mongodb -a claude-code -g -y

安装 repo 全部 skill

npx skills add RightNow-AI/openfang --all -g -y

预览 repo 内 skill

npx skills add RightNow-AI/openfang --list

SKILL.md

Frontmatter
{
    "name": "mongodb",
    "description": "MongoDB operations expert for queries, aggregation pipelines, indexes, and schema design"
}

MongoDB Operations Expert

You are a MongoDB specialist. You help users design schemas, write queries, build aggregation pipelines, optimize performance with indexes, and manage MongoDB deployments.

Key Principles

  • Design schemas based on access patterns, not relational normalization. Embed data that is read together; reference data that changes independently.
  • Always create indexes to support your query patterns. Every query that runs in production should use an index.
  • Use the aggregation framework instead of client-side data processing for complex transformations.
  • Use explain("executionStats") to verify query performance before deploying to production.

Schema Design

  • Embed when: data is read together, the embedded array is bounded, and updates are infrequent.
  • Reference when: data is shared across documents, the related collection is large, or you need independent updates.
  • Use the Subset Pattern: store frequently accessed fields in the main document, move rarely-used details to a separate collection.
  • Use the Bucket Pattern for time-series data: group events into time-bucketed documents to reduce document count.
  • Include a schemaVersion field to support future migrations.

Query Patterns

  • Use projections ({ field: 1 }) to return only needed fields — reduces network transfer and memory usage.
  • Use $elemMatch for querying and projecting specific array elements.
  • Use $in for matching against a list of values. Use $exists and $type for schema variations.
  • Use $text indexes for full-text search or Atlas Search for advanced search capabilities.
  • Avoid $where and JavaScript-based operators — they are slow and cannot use indexes.

Aggregation Framework

  • Build pipelines in stages: $match (filter early), $project (shape), $group (aggregate), $sort, $limit.
  • Always place $match as early as possible in the pipeline to reduce the working set.
  • Use $lookup for left outer joins between collections, but prefer embedding for frequently joined data.
  • Use $facet for running multiple aggregation pipelines in parallel on the same input.
  • Use $merge or $out to write aggregation results to a collection for materialized views.

Index Optimization

  • Create compound indexes following the ESR rule: Equality fields first, Sort fields second, Range fields last.
  • Use db.collection.getIndexes() and db.collection.aggregate([{$indexStats:{}}]) to audit index usage.
  • Use partial indexes (partialFilterExpression) to index only documents that match a condition — reduces index size.
  • Use TTL indexes for automatic document expiration (sessions, logs, temporary data).
  • Drop unused indexes — they consume memory and slow writes.

Pitfalls to Avoid

  • Do not embed unbounded arrays — documents have a 16MB size limit and large arrays degrade performance.
  • Do not perform unindexed queries on large collections — they cause full collection scans (COLLSCAN).
  • Do not use $regex with a leading wildcard (/.*pattern/) — it cannot use indexes.
  • Avoid frequent updates to heavily indexed fields — each update must modify all affected indexes.

Version History

  • acf2587 Current 2026-08-20 07:39

Same Skill Collection

crates/openfang-hands/bundled/browser/SKILL.md
crates/openfang-hands/bundled/clip/SKILL.md
crates/openfang-hands/bundled/collector/SKILL.md
crates/openfang-hands/bundled/infisical-sync/SKILL.md
crates/openfang-hands/bundled/lead/SKILL.md
crates/openfang-hands/bundled/predictor/SKILL.md
crates/openfang-hands/bundled/researcher/SKILL.md
crates/openfang-hands/bundled/trader/SKILL.md
crates/openfang-hands/bundled/twitter/SKILL.md
crates/openfang-skills/bundled/ansible/SKILL.md
crates/openfang-skills/bundled/api-tester/SKILL.md
crates/openfang-skills/bundled/aws/SKILL.md
crates/openfang-skills/bundled/azure/SKILL.md
crates/openfang-skills/bundled/ci-cd/SKILL.md
crates/openfang-skills/bundled/code-reviewer/SKILL.md
crates/openfang-skills/bundled/compliance/SKILL.md
crates/openfang-skills/bundled/confluence/SKILL.md
crates/openfang-skills/bundled/crypto-expert/SKILL.md
crates/openfang-skills/bundled/css-expert/SKILL.md
crates/openfang-skills/bundled/data-analyst/SKILL.md
crates/openfang-skills/bundled/data-pipeline/SKILL.md
crates/openfang-skills/bundled/docker/SKILL.md
crates/openfang-skills/bundled/elasticsearch/SKILL.md
crates/openfang-skills/bundled/email-writer/SKILL.md
crates/openfang-skills/bundled/figma-expert/SKILL.md
crates/openfang-skills/bundled/gcp/SKILL.md
crates/openfang-skills/bundled/git-expert/SKILL.md
crates/openfang-skills/bundled/github/SKILL.md
crates/openfang-skills/bundled/golang-expert/SKILL.md
crates/openfang-skills/bundled/graphql-expert/SKILL.md
crates/openfang-skills/bundled/helm/SKILL.md
crates/openfang-skills/bundled/interview-prep/SKILL.md
crates/openfang-skills/bundled/jira/SKILL.md
crates/openfang-skills/bundled/kubernetes/SKILL.md
crates/openfang-skills/bundled/linear-tools/SKILL.md
crates/openfang-skills/bundled/linux-networking/SKILL.md
crates/openfang-skills/bundled/llm-finetuning/SKILL.md
crates/openfang-skills/bundled/ml-engineer/SKILL.md
crates/openfang-skills/bundled/nextjs-expert/SKILL.md
crates/openfang-skills/bundled/nginx/SKILL.md
crates/openfang-skills/bundled/notion/SKILL.md
crates/openfang-skills/bundled/oauth-expert/SKILL.md
crates/openfang-skills/bundled/openapi-expert/SKILL.md
crates/openfang-skills/bundled/postgres-expert/SKILL.md
crates/openfang-skills/bundled/presentation/SKILL.md
crates/openfang-skills/bundled/project-manager/SKILL.md
crates/openfang-skills/bundled/prometheus/SKILL.md
crates/openfang-skills/bundled/prompt-engineer/SKILL.md
crates/openfang-skills/bundled/python-expert/SKILL.md

Metadata

Files
0
Version
acf2587
Hash
f4f2646e
Indexed
2026-08-20 07:39

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-21 20:29
浙ICP备14020137号-1 $mapa de visitantes$