I know that MongoDB has secondary indexes but from what I can tell they work locally on each shard. This means each shard maintains its own index that only covers the documents stored on that particular shard. When you run a query, all shards check their local indexes at the same time and then combine the results.
I’ve seen that databases like DynamoDB and Couchbase offer global secondary indexes. With this approach, instead of having separate indexes spread across multiple nodes, there’s one centralized index on a single node that covers all the data globally. This lets you do index lookups by hitting just one node instead of multiple ones.
Does MongoDB offer anything like this? I’ve been looking through their documentation but haven’t found any mention of global secondary indexes as a feature.
nope, mongodb doesn’t have true global secondary indexes like dynamodb. each shard maintains its own piece of the index. it’s annoying when you query non-shard key fields because it hits every shard, but that’s mongodb’s trade-off - they chose horizontal scaling over avoiding single-node bottlenecks.
This is actually how MongoDB’s designed to work. I’ve been working with sharded clusters for years, and the distributed indexing makes sense when you think about the trade-offs. A single global index would be a massive bottleneck - every write would have to update that centralized index, killing your write performance across the whole cluster. With distributed indexes, writes can happen in parallel without coordination overhead. Sure, queries without the shard key need scatter-gather operations, but MongoDB’s query planner handles this pretty well. If you really need global secondary index performance, maybe rethink your sharding strategy or use compound indexes with your shard key for targeted queries.
MongoDB does not offer global secondary indexes in the way some other databases do. Each secondary index is partitioned across shards, meaning that every shard maintains its own version of the index limited to its subset of documents. This design choice enhances fault tolerance and scalability because it avoids relying on a single node, which can become a performance bottleneck. While DynamoDB’s global secondary indexes may offer quicker query performance for specific use cases, they can also introduce additional costs and eventual consistency. In contrast, MongoDB’s approach prioritizes overall system resilience and higher write performance as the data scales.