mongodb-query-patterns
CommunityEliminate MongoDB inefficiencies in Mongoose.
System Documentation
What problem does it solve?
Prevents wasteful MongoDB access patterns in Mongoose code by ensuring each document is fetched once, passed through service layers, and queried efficiently (avoiding N+1 queries, looped queries, and overly broad selects).
Core Features & Use Cases
- Hoist and reuse fetched documents: Pass prefetched documents through controller/service chains instead of re-querying by IDs.
- Batch reads and writes: Replace per-item queries in loops with
$inbatching, Map-based lookups, andbulkWritefor updates. - Tighten query performance: Use
.select()for only needed fields,.lean()for read-only paths, and ensure index coverage for filter fields. - Reduce populate-driven N+1: Avoid
.populate()across lists when it triggers hidden per-document queries; batch manually instead.
Use case: You’re reviewing a checkout/order workflow where controllers call multiple services and each service re-fetches the same Order and related documents—refactor the data flow to fetch once, narrow fields, batch list reads, and write updates efficiently.
Quick Start
Apply the mongodb-query-patterns skill while refactoring a Mongoose endpoint to review data flow, remove duplicate queries, batch list operations, and ensure queries use .select(), .lean(), indexing, and bulkWrite where appropriate.
Dependency Matrix
Required Modules
None requiredComponents
Standard packageđź’» Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: mongodb-query-patterns Download link: https://github.com/Thiago-Cruz-eng/Hibrygame/archive/main.zip#mongodb-query-patterns Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.