@@ -94,6 +94,9 @@ preference parameters.
94
94
95
95
A server mode in which the same query is dispatched in parallel to multiple replica set members.
96
96
97
+ > [ !NOTE]
98
+ > Hedged reads are deprecated in MongoDB Server version 8.0.
99
+
97
100
** Immediate topology check**
98
101
99
102
For 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.
126
129
** Read preference**
127
130
128
131
The parameters describing which servers in a deployment can receive read operations, including ` mode ` , ` tag_sets ` ,
129
- ` maxStalenessSeconds ` , and ` hedge ` .
132
+ ` maxStalenessSeconds ` , and ` hedge ` (deprecated) .
130
133
131
134
** RS**
132
135
@@ -312,9 +315,9 @@ the [Rules for server selection](#rules-for-server-selection) section.
312
315
313
316
#### Components of a read preference
314
317
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
318
321
` hedge ` is set, it configures how server hedged reads are used.
319
322
320
323
The 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:
454
457
455
458
##### hedge
456
459
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:
459
462
460
463
- ` enabled` : Enables or disables hedging
461
464
@@ -468,6 +471,10 @@ driver that exposes a builder API for read preference objects MUST NOT allow an
468
471
constructed . In this case, the user MUST specify a value for ` enabled` , which MUST default to ` true` . If the user does
469
472
not call a ` hedge` API method, drivers MUST NOT send a ` hedge` option to the server.
470
473
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
+
471
478
#### Read preference configuration
472
479
473
480
Drivers 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(
488
495
{},
489
496
read_preference=ReadPreference.NEAREST,
490
497
tag_sets=[{'dc': 'ny'}],
491
- maxStalenessSeconds=120,
492
- hedge={'enabled': true})
498
+ maxStalenessSeconds=120)
493
499
` ` `
494
500
495
501
< 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
519
525
- For mode ' secondary' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
520
526
- For mode ' primaryPreferred' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
521
527
- 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`
524
530
- For mode ' nearest' , drivers MUST set the ` SecondaryOk` wire protocol flag and MUST also use ` $readPreference`
525
531
526
532
The ` $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:
538
544
$readPreference: {
539
545
mode: 'secondary',
540
546
tags: [ { 'dc': 'ny' } ],
541
- maxStalenessSeconds: 120,
542
- hedge: { enabled: true }
547
+ maxStalenessSeconds: 120
543
548
}
544
549
}
545
550
` ` `
@@ -1263,7 +1268,7 @@ def getServer(criteria):
1263
1268
else if loopEndTime > maxTime:
1264
1269
throw server selection error with details
1265
1270
1266
- if the message was not logged already:
1271
+ if the message was not logged already:
1267
1272
log a "waiting for suitable server to become available" message
1268
1273
```
1269
1274
@@ -1679,5 +1684,7 @@ maxStalenessSeconds first, then tag_sets, and select Node 2.
1679
1684
1680
1685
- 2024 - 02 - 07 : Migrated from reStructuredText to Markdown.
1681
1686
1687
+ - 2025 - 02 - 25 : Note the deprecation of hedged reads.
1688
+
1682
1689
[^ 1 ]: mongos 3.4 refuses to connect to mongods with maxWireVersion \< 5 , so it does no additional wire version checks
1683
1690
related to maxStalenessSeconds.
0 commit comments