MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / ReadPreference

Class ReadPreference

pymongo/read_preferences.py:547–606  ·  view source on GitHub ↗

An enum that defines some commonly used read preference modes. Apps can also create a custom read preference, for example:: Nearest(tag_sets=[{"node":"analytics"}]) See `Read and Write Settings <https://www.mongodb.com/docs/languages/python/pymongo-driver/current/crud/configure/#re

Source from the content-addressed store, hash-verified

545
546
547class ReadPreference:
548 """An enum that defines some commonly used read preference modes.
549
550 Apps can also create a custom read preference, for example::
551
552 Nearest(tag_sets=[{"node":"analytics"}])
553
554 See `Read and Write Settings <https://www.mongodb.com/docs/languages/python/pymongo-driver/current/crud/configure/#read-and-write-settings>`_ for code examples.
555
556 A read preference is used in three cases:
557
558 :class:`~pymongo.mongo_client.MongoClient` connected to a single mongod:
559
560 - ``PRIMARY``: Queries are allowed if the server is standalone or a replica
561 set primary.
562 - All other modes allow queries to standalone servers, to a replica set
563 primary, or to replica set secondaries.
564
565 :class:`~pymongo.mongo_client.MongoClient` initialized with the
566 ``replicaSet`` option:
567
568 - ``PRIMARY``: Read from the primary. This is the default, and provides the
569 strongest consistency. If no primary is available, raise
570 :class:`~pymongo.errors.AutoReconnect`.
571
572 - ``PRIMARY_PREFERRED``: Read from the primary if available, or if there is
573 none, read from a secondary.
574
575 - ``SECONDARY``: Read from a secondary. If no secondary is available,
576 raise :class:`~pymongo.errors.AutoReconnect`.
577
578 - ``SECONDARY_PREFERRED``: Read from a secondary if available, otherwise
579 from the primary.
580
581 - ``NEAREST``: Read from any member.
582
583 :class:`~pymongo.mongo_client.MongoClient` connected to a mongos, with a
584 sharded cluster of replica sets:
585
586 - ``PRIMARY``: Read from the primary of the shard, or raise
587 :class:`~pymongo.errors.OperationFailure` if there is none.
588 This is the default.
589
590 - ``PRIMARY_PREFERRED``: Read from the primary of the shard, or if there is
591 none, read from a secondary of the shard.
592
593 - ``SECONDARY``: Read from a secondary of the shard, or raise
594 :class:`~pymongo.errors.OperationFailure` if there is none.
595
596 - ``SECONDARY_PREFERRED``: Read from a secondary of the shard if available,
597 otherwise from the shard primary.
598
599 - ``NEAREST``: Read from any shard member.
600 """
601
602 PRIMARY = Primary()
603 PRIMARY_PREFERRED = PrimaryPreferred()
604 SECONDARY = Secondary()

Callers

nothing calls this directly

Calls 5

PrimaryClass · 0.85
PrimaryPreferredClass · 0.85
SecondaryClass · 0.85
SecondaryPreferredClass · 0.85
NearestClass · 0.85

Tested by

no test coverage detected