mcpField
M
mongodb-usage

mongodb-usage

github.com/fcakyonData & databases1.2k47 installsUpdated today
Repository

About mongodb-usage

A MongoDB best-practices skill for developers making schema, index, aggregation, and connection decisions. It focuses on practical design guidance and explicitly describes the associated MCP operation as read-only.

Key features

  1. 01Embedding and referencing guidance
  2. 02Common document schema patterns
  3. 03Index types and ESR ordering
  4. 04Aggregation pipeline performance tips
  5. 05Connection and pooling recommendations
  6. 06Read-only MCP operation

Use cases

  1. 01Choose between embedding and references
  2. 02Plan indexes for query and sort patterns
  3. 03Improve aggregation pipeline efficiency

MCP support

The input describes the MCP operation as read-only; write, update, and delete operations are unavailable. It provides MongoDB best-practice guidance.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fcakyon/claude-codex-settings --skill mongodb-usage

After installing, type/mongodb-usagein Claude Code to confirm it loaded.

Details

From the project README

MongoDB Best Practices

MCP Limitation

This MCP operates in READ-ONLY mode. No write, update, or delete operations are possible.

Schema Design Patterns

Embedding vs Referencing

Embed when:

  • Data is accessed together frequently
  • Child documents are bounded (won't grow unbounded)
  • One-to-few relationships
  • Data doesn't change frequently

Reference when:

  • Data is accessed independently
  • Many-to-many relationships
  • Documents would exceed 16MB limit
  • Frequent updates to referenced data
Common Patterns

Subset pattern: Store frequently accessed subset in parent, full data in separate collection.

Bucket pattern: Group time-series data into buckets (e.g., hourly readings in one document).

Computed pattern: Store pre-computed values for expensive calculations.

Index Strategies

Index Guidelines
  • Index fields used in queries, sorts, and aggregation $match stages
  • Compound indexes support queries on prefix fields
  • Covered queries (all fields in index) are fastest
  • Too many indexes slow writes
Index Types
  • Single field: Basic index on one field
  • Compound: Multiple fields, order matters for queries
  • Multikey: Automatically created for array fields
  • Text: Full-text search on string content
  • TTL: Auto-expire documents after time period
ESR Rule

For compound indexes, order fields by:

  1. Equality (exact match fields)
  2. Sort (sort order fields)
  3. Range (range query fields like $gt, $lt)

Aggregation Pipeline

Performance Tips
  • Put $match and $project early to reduce documents
  • Use $limit early when possible
  • Avoid $lookup on large collections without indexes
  • Use $facet for multiple aggregations in one query
Common Stages
// Filter documents
{ $match: { status: "active" } }

// Reshape documents
{ $project: { name: 1, total: { $sum: "$items.price" } } }

// Group and aggregate
{ $group: { _id: "$category", count: { $sum: 1 } } }

// Sort results
{ $sort: { count: -1 } }

// Join collections
{ $lookup: { from: "orders", localField: "_id", foreignField: "userId", as: "orders" } }

Connection Best Practices

Connection String Formats
  • Atlas: mongodb+srv://user:[email protected]/database
  • Local: mongodb://localhost:27017/database
  • Replica set: mongodb://host1,host2,host3/database?replicaSet=rs0
Connection Pooling
  • Use connection pooling in applications (default in drivers)
  • Set appropriate pool size for your workload
  • Don't create new connections per request

Anti-Patterns to Avoid

  • Unbounded arrays: Arrays that grow without limit
  • Massive documents: Documents approaching 16MB
  • Too many collections: Use embedding instead
  • Missing indexes: Queries doing collection scans
  • $where operator: Use aggregation instead for security
  • Storing files in documents: Use GridFS for large files

Comments

Markdown supported