Can a compound index replace multiple single indexes?
Partially. A compound index on (A, B) can serve queries on A and queries on A+B. So it can replace a single index on A. But it cannot serve queries on B alone (prefix rule). You might still need a separate index on B.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in When to Use Indexes in MongoDB (and When Not To)
When you query or sort by a field often, need uniqueness, paginate, filter on multiple fields together, do full-text search, or do geo queries. Use explain() to confirm a query scans many docs before adding an index.
When the collection is small (< 1000 docs), you rarely query by that field, writes are very frequent, or the query is already fast. Every index adds write, storage, and memory overhead. Do not index every field.
List the queries you run. For each, check with explain() how many docs it scans. If a query scans many docs, add an index for it. Re-run explain() to confirm. Repeat as the app evolves.
Still have questions?
Browse all our FAQs or reach out to our support team
