Course contentsShow
← System Design
Lesson 408 of 1,91911. NoSQL: Document StoresFree lesson

Query Performance Limitations

Understanding when complex queries or aggregations across fields become inefficient in document stores.

Query Performance Limitations

You'll learn: When complex queries or aggregations become inefficient in document stores, even with indexing.

The Performance Wall

Document stores excel at retrieving whole documents by ID or indexed fields. However, when you need to perform complex queries—joining data across collections, aggregating values from many documents with multiple conditions, or filtering on combinations of unindexed fields—performance can degrade rapidly.

Think of a document store like a filing cabinet organized by folder labels. Finding a specific folder is fast. But if you need to open every folder, read every page, count specific words, and summarize results across thousands of folders? That becomes slow manual labor.

Why Complex Queries Struggle

Collection scans: Without the right index, queries must examine every document. In a collection with millions of documents, this becomes prohibitively expensive.

Aggregation overhead: Computing sums, averages, or counts across large datasets requires reading many documents into memory. Unlike columnar databases optimized for analytics, document stores read entire documents even if you only need one field.

No query optimization: Document stores lack the sophisticated query planners found in relational databases that can rewrite queries, choose optimal join strategies, or parallelize operations efficiently.

Cross-collection operations: Since document stores discourage joins, fetching related data often requires multiple round-trips or application-level logic, multiplying latency.

The Practical Impact

A query like "find all users in California who made purchases over $100 in the last month and group by product category" might work fine with 1,000 documents but timeout with 1 million—unless you've carefully pre-indexed every field combination or pre-aggregated the data.

Key Takeaway: Document stores optimize for simple, predictable queries on indexed fields; complex ad-hoc queries, multi-field aggregations, and analytical workloads often require separate tools or careful data modeling to maintain performance at scale.