$exists query bounds on indexes
Parent: MongoDB Compound Index Design: ESR, Selectivity, Covering and Multikey Bounds · Published reference · snapshot 2026-10-21 · skill ranked-29798f23
↓ Facts as markdownall context files
Source-anchored research for $exists query bounds on indexes. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Structure and components
- An all-ascending/descending compound sparse index includes a document when at least one indexed key has a value. Index membership therefore does not by itself prove that every individual component exists; the exact sparse-index claim above is limited to a single-field index. (low confidence) (verified as of 2026-10-14) [source]
How it works
- $exists:true matches documents where the field is present, including an explicit null value; $exists:false matches only documents where the field is absent. A null equality query is different because it also matches missing fields. (high confidence) (verified as of 2026-10-21) [source]
Problems, failure modes and limitations
- A sparse index on f cannot answer {f: {$exists: false}} because it omits the matching missing-field documents, so MongoDB requires a COLLSCAN for that index. A non-sparse index can scan the null-key candidates and use FETCH to distinguish absent fields from explicitly-null fields; the optimizer may still prefer a collection scan. (medium confidence) (verified as of 2026-10-18) [source]
- A partial index filtered by {f: {$exists: true}} only covers documents where f exists. MongoDB uses a partial index only when the query implies its filter, so that index cannot answer {f: {$exists: false}} without omitting matches. (medium confidence) (verified as of 2026-10-14) [source]
Facts and statements
- For a single-field sparse index on f, {f: {$exists: true}} can use the full [MinKey, MaxKey] range as an exact existence test: missing fields have no index entries, but explicit null values do. MongoDB does not need a FETCH just to recheck existence, though it may fetch documents to return fields that are not covered by the index. (high confidence) (verified as of 2026-10-18) [source]
- A non-sparse single-field index stores a null-like key for documents missing f. Therefore, {f: {$exists: true}} has no selective value bound from existence alone: an observed IXSCAN spans [MinKey, MaxKey] and FETCH applies the $exists filter, examining all index entries and documents. (high confidence) (verified as of 2026-10-18) [source]
Children
- No children recorded.