Secondary read preference. * When directly connected to one mongod queries are allowed to standalone servers, to a replica set primary, or to replica set secondaries. * When connected to a mongos queries are distributed among shard secondaries. An error is raised if no secondari
| 353 | |
| 354 | |
| 355 | class Secondary(_ServerMode): |
| 356 | """Secondary read preference. |
| 357 | |
| 358 | * When directly connected to one mongod queries are allowed to standalone |
| 359 | servers, to a replica set primary, or to replica set secondaries. |
| 360 | * When connected to a mongos queries are distributed among shard |
| 361 | secondaries. An error is raised if no secondaries are available. |
| 362 | * When connected to a replica set queries are distributed among |
| 363 | secondaries. An error is raised if no secondaries are available. |
| 364 | |
| 365 | :param tag_sets: The :attr:`~tag_sets` for this read preference. |
| 366 | :param max_staleness: (integer, in seconds) The maximum estimated |
| 367 | length of time a replica set secondary can fall behind the primary in |
| 368 | replication before it will no longer be selected for operations. |
| 369 | Default -1, meaning no maximum. If it is set, it must be at least |
| 370 | 90 seconds. |
| 371 | :param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. |
| 372 | |
| 373 | .. versionchanged:: 3.11 |
| 374 | Added ``hedge`` parameter. |
| 375 | """ |
| 376 | |
| 377 | __slots__ = () |
| 378 | |
| 379 | def __init__( |
| 380 | self, |
| 381 | tag_sets: Optional[_TagSets] = None, |
| 382 | max_staleness: int = -1, |
| 383 | hedge: Optional[_Hedge] = None, |
| 384 | ) -> None: |
| 385 | super().__init__(_SECONDARY, tag_sets, max_staleness, hedge) |
| 386 | |
| 387 | def __call__(self, selection: Selection) -> Selection: |
| 388 | """Apply this read preference to Selection.""" |
| 389 | return secondary_with_tags_server_selector( |
| 390 | self.tag_sets, max_staleness_selectors.select(self.max_staleness, selection) |
| 391 | ) |
| 392 | |
| 393 | |
| 394 | class SecondaryPreferred(_ServerMode): |
no outgoing calls