The story in one sentence: settings that used to live only at the cluster level can now travel with a single command, and settings that used to bound a single command can now live at the shape level. Three pieces make that up.
Inline querySettings on a command
find, distinct and aggregate accept a querySettings document in 9.0. The setting applies
to that execution only - nothing is stored, nothing applies to the next query with the same shape:
// try a particular index for this execution only
db.orders.find(
{ status: "paid", currency: "EUR", amount: { $gte: 10 } },
{ querySettings: { indexHints: { allowedIndexes: ["status_1_currency_1"] } } }
)
That is the answer to “does this index actually help” without creating a stored rule first - run
the command with the hint, read the explain, decide. The shape-level path still exists through
setQuerySettings, and when both apply, the stored cluster setting wins on any field they both
specify - the inline document is not a way to overrule stored settings.
queryKnobs: internal parameters, per shape
queryKnobs is a query setting that overrides internal server parameters for a single query
shape - the parameters that previously required a setParameter against the whole process. It
needs feature compatibility version 9.0 or later, and it is aimed at exactly the situation that
used to force a global flag: one shape that needs different costing or memory behaviour from the
fleet.
// bound one recurring reporting shape without touching global parameters
db.adminCommand({
setQuerySettings: {
find: "reports",
filter: { "metrics.week": { $eq: "$$NOW" } }
},
settings: {
querySettings: {
indexHints: { allowedIndexes: ["metrics_week_1"] }
}
}
})
Per-shape maxTimeMS
setQuerySettings accepts maxTimeMS in 9.0, which puts a time budget on every query matching a
shape - not just the one call where you remembered to pass it. Where a reporting query that
usually finishes in seconds occasionally runs for minutes, the shape-level budget caps the tail
without an application change:
db.adminCommand({
setQuerySettings: { find: "reports", filter: { kind: "nightly" } },
settings: { maxTimeMS: 5000 }
})
Both queryKnobs and per-shape maxTimeMS sit behind FCV 9.0 - a cluster partway through an
upgrade will not accept them until the FCV is bumped.
Where it breaks
- Assuming inline beats stored - the stored cluster setting wins field-for-field; an inline
setting that contradicts a stored one silently loses, and
EXPLAINis the way to see which was applied. - Forgetting FCV -
queryKnobsand per-shapemaxTimeMSare rejected below FCV 9.0, which is most pre-upgrade clusters and any cluster mid-upgrade. - Over-broad shapes - a shape is the normalised form of the query; a setting meant for one
endpoint can catch every query that normalises the same way. Inspect
planCacheShapes/$queryStatsbefore storing one. - maxTimeMS on a write path - the budget applies to read shapes; do not expect it to govern a transaction.
What this is not for
- General tuning - these are surgical controls for individual shapes; planner behaviour, index design and the engine page’s fundamentals come first.
- Replacing application timeouts - per-shape
maxTimeMSis a server-side floor, not a substitute for client-side deadline propagation.
MongoDB release support
4 supported| Release | Latest | Released |
|---|---|---|
9.0 | 9.0.8 | Sept 2026 |
8.3 | 8.3.17 | May 2026 |
8.0 | 8.0.38 | Oct 2024 |
7.0 | 7.0.48 | Aug 2023 |
Data as of 2026-11-21 from endoflife.date. Refresh with node scripts/fetch-versions.mjs.
Where MongoDB sits
How this component relates to the rest of the stack. Items without a link are not covered here yet.