Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé
Module « pymongo »

Classe « ReadPreference »

Informations générales

Héritage

builtins.object
    ReadPreference

Définition

class ReadPreference(builtins.object):

help(ReadPreference)

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 :doc:`/examples/high_availability` for code examples.

A read preference is used in three cases:

:class:`~pymongo.mongo_client.MongoClient` connected to a single mongod:

- ``PRIMARY``: Queries are allowed if the server is standalone or a replica
  set primary.
- All other modes allow queries to standalone servers, to a replica set
  primary, or to replica set secondaries.

:class:`~pymongo.mongo_client.MongoClient` initialized with the
``replicaSet`` option:

- ``PRIMARY``: Read from the primary. This is the default, and provides the
  strongest consistency. If no primary is available, raise
  :class:`~pymongo.errors.AutoReconnect`.

- ``PRIMARY_PREFERRED``: Read from the primary if available, or if there is
  none, read from a secondary.

- ``SECONDARY``: Read from a secondary. If no secondary is available,
  raise :class:`~pymongo.errors.AutoReconnect`.

- ``SECONDARY_PREFERRED``: Read from a secondary if available, otherwise
  from the primary.

- ``NEAREST``: Read from any member.

:class:`~pymongo.mongo_client.MongoClient` connected to a mongos, with a
sharded cluster of replica sets:

- ``PRIMARY``: Read from the primary of the shard, or raise
  :class:`~pymongo.errors.OperationFailure` if there is none.
  This is the default.

- ``PRIMARY_PREFERRED``: Read from the primary of the shard, or if there is
  none, read from a secondary of the shard.

- ``SECONDARY``: Read from a secondary of the shard, or raise
  :class:`~pymongo.errors.OperationFailure` if there is none.

- ``SECONDARY_PREFERRED``: Read from a secondary of the shard if available,
  otherwise from the shard primary.

- ``NEAREST``: Read from any shard member.

Constructeur(s)

Signature du constructeur Description
__init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. [extrait de __init__.__doc__]

Liste des opérateurs

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
NEAREST(selection: 'Selection') -> 'Selection' Nearest read preference. [extrait de __doc__]
PRIMARY(selection: 'Selection') -> 'Selection' Primary read preference. [extrait de __doc__]
PRIMARY_PREFERRED(selection: 'Selection') -> 'Selection' PrimaryPreferred read preference. [extrait de __doc__]
SECONDARY(selection: 'Selection') -> 'Selection' Secondary read preference. [extrait de __doc__]
SECONDARY_PREFERRED(selection: 'Selection') -> 'Selection' SecondaryPreferred read preference. [extrait de __doc__]

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __init_subclass__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé