@@ -94,6 +94,9 @@ preference parameters.
9494
9595A server mode in which the same query is dispatched in parallel to multiple replica set members.
9696
97+ > [ !NOTE]
98+ > Hedged reads are deprecated in MongoDB Server version 8.0.
99+
97100** Immediate topology check**
98101
99102For a multi-threaded or asynchronous client, this means waking all server monitors for an immediate check. For a
@@ -126,7 +129,7 @@ An OP_QUERY operation targeting a regular (non '$cmd') collection namespace.
126129** Read preference**
127130
128131The parameters describing which servers in a deployment can receive read operations, including ` mode ` , ` tag_sets ` ,
129- ` maxStalenessSeconds ` , and ` hedge ` .
132+ ` maxStalenessSeconds ` , and ` hedge ` (deprecated) .
130133
131134** RS**
132135
@@ -312,9 +315,9 @@ the [Rules for server selection](#rules-for-server-selection) section.
312315
313316#### Components of a read preference
314317
315- A read preference consists of a ` mode ` and optional ` tag_sets ` , ` maxStalenessSeconds ` , and ` hedge ` . The ` mode `
316- prioritizes between primaries and secondaries to produce either a single suitable server or a list of candidate servers.
317- If ` tag_sets ` and ` maxStalenessSeconds ` are set, they determine which candidate servers are eligible for selection. If
318+ A read preference consists of a ` mode ` and optional ` tag_sets ` , ` maxStalenessSeconds ` , and ` hedge ` (deprecated) . The
319+ ` mode ` prioritizes between primaries and secondaries to produce either a single suitable server or a list of candidate
320+ servers. If ` tag_sets ` and ` maxStalenessSeconds ` are set, they determine which candidate servers are for selection. If
318321` hedge ` is set, it configures how server hedged reads are used.
319322
320323The default ` mode ` is 'primary'. The default ` tag_sets ` is a list with an empty tag set: ` [{}] ` . The default
@@ -454,8 +457,8 @@ Eligibility MUST be determined from `tag_sets` as follows:
454457
455458##### hedge
456459
457- The read preference ` hedge` parameter is a document that configures how the server will perform hedged reads . It
458- consists of the following keys:
460+ The deprecated read preference ` hedge` parameter is a document that configures how the server will perform hedged reads.
461+ It consists of the following keys:
459462
460463- ` enabled` : Enables or disables hedging
461464
@@ -468,6 +471,10 @@ driver that exposes a builder API for read preference objects MUST NOT allow an
468471constructed . In this case, the user MUST specify a value for ` enabled` , which MUST default to ` true` . If the user does
469472not call a ` hedge` API method, drivers MUST NOT send a ` hedge` option to the server.
470473
474+ Driver APIs related to the ` hedge` parameter SHOULD be annotated and documented as deprecated . If static annotations are
475+ not used, drivers MUST emit a runtime deprecation warning if a ` hedge` parameter is specified . Such deprecation warnings
476+ should note that hedged reads are deprecated in MongoDB Server 8.0 and will be removed in a future version.
477+
471478#### Read preference configuration
472479
473480Drivers MUST allow users to configure a default read preference on a ` MongoClient` object . Drivers MAY allow users to
@@ -488,8 +495,7 @@ db.collection.find(
488495 {},
489496 read_preference=ReadPreference.NEAREST,
490497 tag_sets=[{'dc': 'ny'}],
491- maxStalenessSeconds=120,
492- hedge={'enabled': true})
498+ maxStalenessSeconds=120)
493499` ` `
494500
495501< span id= " passing-read-preference-to-mongos" >< / span>
@@ -519,8 +525,8 @@ Therefore, when sending queries to a mongos or load balancer, the following rule
519525- For mode ' secondary' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
520526- For mode ' primaryPreferred' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
521527- For mode ' secondaryPreferred' , drivers MUST set the ` SecondaryOk` wire protocol flag . If the read preference contains
522- a non- empty ` tag_sets` parameter, ` maxStalenessSeconds` is a positive integer, or the ` hedge` parameter is
523- non- empty, drivers MUST use ` $readPreference` ; otherwise, drivers MUST NOT use ` $readPreference`
528+ a non- empty ` tag_sets` parameter, ` maxStalenessSeconds` is a positive integer, or the deprecated ` hedge` parameter
529+ is non- empty, drivers MUST use ` $readPreference` ; otherwise, drivers MUST NOT use ` $readPreference`
524530- For mode ' nearest' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
525531
526532The ` $readPreference` query modifier sends the read preference as part of the query . The read preference fields
@@ -538,8 +544,7 @@ query MUST be provided using the `$query` modifier like so:
538544 $readPreference: {
539545 mode: 'secondary',
540546 tags: [ { 'dc': 'ny' } ],
541- maxStalenessSeconds: 120,
542- hedge: { enabled: true }
547+ maxStalenessSeconds: 120
543548 }
544549}
545550` ` `
@@ -1263,7 +1268,7 @@ def getServer(criteria):
12631268 else if loopEndTime > maxTime:
12641269 throw server selection error with details
12651270
1266- if the message was not logged already:
1271+ if the message was not logged already:
12671272 log a "waiting for suitable server to become available" message
12681273```
12691274
@@ -1679,5 +1684,7 @@ maxStalenessSeconds first, then tag_sets, and select Node 2.
16791684
16801685- 2024 - 02 - 07 : Migrated from reStructuredText to Markdown.
16811686
1687+ - 2025 - 02 - 25 : Note the deprecation of hedged reads.
1688+
16821689[^ 1 ]: mongos 3.4 refuses to connect to mongods with maxWireVersion \< 5 , so it does no additional wire version checks
16831690 related to maxStalenessSeconds.
0 commit comments