本文へスキップ
Skillpedia
データベース18k · #10691

mongodb

できること

このスキルは、スキーマ設計、クエリ、集計パイプライン、インデックスを含め、MongoDBの使い方を案内します。アプリのデータをMongoDBに保存する開発者向けです。

使う場面

  • ✓新しいアプリのMongoDBスキーマを設計しているとき。
  • ✓MongoDBのクエリが遅く、インデックスや適切なプロジェクションが必要なとき。
  • ✓集計パイプラインでデータを要約または変換する必要があるとき。

スキルのリンク

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/mongodb/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/mongodb/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“注文と顧客のMongoDBスキーマを設計してください。顧客の最近の注文を検索できるように、インデックスも追加してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、データの読まれ方に基づいて埋め込みと参照を選び、各クエリに必要なインデックスを推奨します。また、クエリプランを確認することも勧めます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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.
よくある質問

データはいつ埋め込むべきですか?

データが一緒に読まれ、配列の大きさが限られていて、更新がまれな場合に埋め込むことを勧めています。

なぜクエリプランを確認するのですか?

本番に出す前に実行統計を確認し、クエリがインデックスを使っているかを確かめることを勧めているためです。

スキーマのバージョンフィールドを追加するのはなぜですか?

各ドキュメントがどのスキーマに従うかがわかるため、将来のマイグレーションが管理しやすくなるからです。

詳細

作者による元の説明

MongoDB operations expert for queries, aggregation pipelines, indexes, and schema design

repo: RightNow-AI/openfang

人気

GitHubのスター
18k
ランキング
#10691
ライセンス
Apache-2.0
更新日
2026/7/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル