database-mongodb

Installation
SKILL.md

MongoDB Best Practices

Priority: P0 (CRITICAL)

Schema Design

  • Embed vs Reference:
  • Embed (1:Few): Addresses, Phone Numbers. Optimization: Read locality.
  • Reference (1:Many/Infinity): Logs, Activity History. Optimization: Document size limits (16MB).
  • Bucket Pattern: For time-series or high-cardinality "One-to-Many", bucket items into documents (e.g., DailyLog).

Optimize Indexes

  • ESR Rule: Equality, Sort, Range. Order your index keys (status, date, price) if you query status='A', sort by date, filter price > 10.

See implementation examples for compound index and pagination patterns.

  • Text Search: Use $text search instead of $regex for keywords. $regex slow (linear scan) unless anchored (^prefix).
  • Covered Queries: Project only indexed fields to avoid fetching document (PROJECTION key).
  • Explain Plan: Target nReturned / keysExamined ratio of ~1. If docsExamined >> nReturned, index inefficient.
Installs
1
GitHub Stars
521
First Seen
7 days ago
database-mongodb — hoangnguyen0403/agent-skills-standard