Nearest 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 all members of a shard. * When connected to a repli
| 440 | |
| 441 | |
| 442 | class Nearest(_ServerMode): |
| 443 | """Nearest read preference. |
| 444 | |
| 445 | * When directly connected to one mongod queries are allowed to standalone |
| 446 | servers, to a replica set primary, or to replica set secondaries. |
| 447 | * When connected to a mongos queries are distributed among all members of |
| 448 | a shard. |
| 449 | * When connected to a replica set queries are distributed among all |
| 450 | members. |
| 451 | |
| 452 | :param tag_sets: The :attr:`~tag_sets` for this read preference. |
| 453 | :param max_staleness: (integer, in seconds) The maximum estimated |
| 454 | length of time a replica set secondary can fall behind the primary in |
| 455 | replication before it will no longer be selected for operations. |
| 456 | Default -1, meaning no maximum. If it is set, it must be at least |
| 457 | 90 seconds. |
| 458 | :param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. |
| 459 | |
| 460 | .. versionchanged:: 3.11 |
| 461 | Added ``hedge`` parameter. |
| 462 | """ |
| 463 | |
| 464 | __slots__ = () |
| 465 | |
| 466 | def __init__( |
| 467 | self, |
| 468 | tag_sets: Optional[_TagSets] = None, |
| 469 | max_staleness: int = -1, |
| 470 | hedge: Optional[_Hedge] = None, |
| 471 | ) -> None: |
| 472 | super().__init__(_NEAREST, tag_sets, max_staleness, hedge) |
| 473 | |
| 474 | def __call__(self, selection: Selection) -> Selection: |
| 475 | """Apply this read preference to Selection.""" |
| 476 | return member_with_tags_server_selector( |
| 477 | self.tag_sets, max_staleness_selectors.select(self.max_staleness, selection) |
| 478 | ) |
| 479 | |
| 480 | |
| 481 | class _AggWritePref: |
no outgoing calls