MongoDB Review
Review MongoDB for aggregation optimization, indexing (ESR rule), sharding, schema design, and security.
Key Checks
- explain("executionStats") on pipelines — $match/$sort early, flag COLLSCAN
- Compound indexes follow ESR: Equality first, Sort second, Range last
- Text indexes for search, wildcard for dynamic schemas, TTL for expiring docs
- Shard key: high cardinality, even distribution, present in all queries; flag jumbo chunks
- Schema: embed for 1:few read-together data, reference for unbounded arrays or independent access
- Bucket pattern for time-series, outlier pattern for large arrays
- Change streams with resume tokens, sufficient oplog size (24-48h)
- w:"majority" write concern, readConcern:"majority", retryWrites:true
- Authentication enabled, TLS enforced, no root role for app, bindIp restricted
Output
Severity-sorted: CRITICAL, HIGH, MEDIUM, LOW, PASSED.
1---2name: mongodb-review3description: Review MongoDB schemas, aggregation pipelines, indexes, and configuration for performance and production readiness4agent: database-reviewer5argument-hint: "<file-or-collection-or-pipeline>"6tags: [database, mongodb, nosql, performance, indexing]7user-invocable: true8---910# MongoDB Review1112Review MongoDB for aggregation optimization, indexing (ESR rule), sharding, schema design, and security.1314## Key Checks15- explain("executionStats") on pipelines — $match/$sort early, flag COLLSCAN16- Compound indexes follow ESR: Equality first, Sort second, Range last17- Text indexes for search, wildcard for dynamic schemas, TTL for expiring docs18- Shard key: high cardinality, even distribution, present in all queries; flag jumbo chunks19- Schema: embed for 1:few read-together data, reference for unbounded arrays or independent access20- Bucket pattern for time-series, outlier pattern for large arrays21- Change streams with resume tokens, sufficient oplog size (24-48h)22- w:"majority" write concern, readConcern:"majority", retryWrites:true23- Authentication enabled, TLS enforced, no root role for app, bindIp restricted2425## Output26Severity-sorted: CRITICAL, HIGH, MEDIUM, LOW, PASSED.