natural hint and collection scans
Parent: MongoDB Explain Plans, Query Planner and Plan Cache · Published reference · snapshot 2026-10-21 · skill ranked-8f7c06b1
↓ Facts as markdownall context files
Source-anchored research for natural hint and collection scans. 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
- MongoDB defines $natural order as an internal implementation feature and says not to rely on a particular document order; use an explicit field sort when order is part of the application's result contract. (high confidence) [source]
How it works
- A 2024 study reported that MongoDB 7.0.1's first-past-the-post planner sometimes preferred index scans when the researchers measured collection scans as faster; this version-specific result does not establish behavior in newer releases. (low confidence) (verified as of 2024-09-25) [source]
- The current MongoDB Database Tools mongodump source adds { $natural: 1 } only when the dump query is unfiltered. Its code comments describe this as declaring an intentional full collection scan that avoids maxEstimatedScanBytes rejection without changing the plan the server would otherwise select. (high confidence) (verified as of 2026-10-21) [source]
Problems, failure modes and limitations
- MongoDB Server 9.0 introduced maxEstimatedScanBytes, which can reject an unbounded COLLSCAN when the collection exceeds the configured threshold. The parameter is disabled by default. When enabled, a $natural hint explicitly overrides that rejection; an effective positive $limit also avoids it by bounding the scan. (high confidence) (verified as of 2026-09-25) [source]
Comparisons and alternatives
- When MongoDB honors the hint, cursor.hint({$natural: 1}) forces a forward collection scan and cursor.hint({$natural: -1}) forces a reverse collection scan; the planner builds a collection-scan plan rather than choosing a regular secondary index. (high confidence) (verified as of 2026-10-21) [source]
Facts and statements
- A COLLSCAN alone does not prove that the planner chose a bad plan: Percona's low-selectivity boolean example found an index scan no faster than a collection scan, and OneUptime recommends comparing executionStats for hinted and unhinted plans before forcing a plan. (medium confidence) [source]
- On one WiredTiger instance, natural order follows the stored recordIds. Replica-set members are not guaranteed to have the same natural order. Sharded collections have no defined natural order, although a $natural hint still makes each shard perform a collection scan. (high confidence) (verified as of 2026-10-21) [source]
- In explain output, queryPlanner.winningPlan.stage: COLLSCAN identifies a collection scan. With executionStats, totalDocsExamined reports documents scanned, totalKeysExamined reports index keys scanned, and nReturned reports matches; compare these values to evaluate scan volume. (high confidence) [source]
- In experiments on MongoDB 7.0.1, University of Sydney researchers found cases where collection scans ran faster than index scans. Their analysis also found that a matching index could keep COLLSCAN out of the candidate plans unless a collection scan was explicitly requested. Treat $natural as a way to test an intentional scan, not as a general performance optimization. (medium confidence) (verified as of 2024-09-25) [source]
Children
- No children recorded.