Database Query Optimization

Optimize Meters collection analytics queries with cursor-based aggregation and batching.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/A-Hazzard/Casino-Manangement-System --skill database-query-optimization-a-hazzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Database Query Optimization
Source: https://github.com/A-Hazzard/Casino-Manangement-System/tree/main/.claude/skills/database-query-optimization
Command: npx skills add https://github.com/A-Hazzard/Casino-Manangement-System --skill database-query-optimization-a-hazzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill reduces memory usage and latency for large Meters aggregations by enforcing cursor-based processing, avoiding expensive lookups, and eliminating N+1 query patterns while properly applying per-location gaming day offsets.

Core Features & Use Cases

  • Cursor-based aggregation improves memory efficiency and performance for multi-location date ranges (7d/30d periods) by streaming results in batches.
  • Direct access to the location field avoids costly $lookup joins, speeding up group-by operations.
  • Batch processing with per-location gaming day offsets ensures accurate, scalable analytics across many locations for dashboards and reports.

Quick Start

Execute the cursor-based aggregation with an appropriate batch size to stream results for all locations across the target date range.

Frequently Asked Questions about Database Query Optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize MongoDB aggregations for large date ranges without running out of memory?

MongoDB aggregations can be optimized by enforcing cursor-based processing, which streams results in batches to maintain memory efficiency. This approach avoids loading large result sets into memory all at once during multi-location data retrieval.

What's the best way to eliminate N+1 query patterns in MongoDB location aggregations?

Eliminating N+1 query patterns requires replacing iterative lookups with direct field access on the location field. This avoids costly $lookup joins and significantly speeds up group-by operations across multiple locations.

How do you handle per-location gaming day offsets in MongoDB analytics queries?

Per-location gaming day offsets are handled within batch processing during cursor streaming, ensuring accurate analytics across many locations without requiring expensive join operations or separate offset calculations.

When do I need to apply allowDiskUse and maxTimeMS in MongoDB aggregations?

Apply allowDiskUse and maxTimeMS when executing large cursor-based aggregations across multi-location date ranges to prevent memory overflow errors and enforce query execution timeouts for scalable analytics.

Does cursor-based aggregation work well for 7d and 30d reporting dashboards?

Cursor-based aggregation improves performance and memory efficiency for 7d and 30d reporting dashboards by streaming large multi-location results in batches rather than executing memory-intensive single returns.