topology_description – An object representation of a deployment of MongoDB servers.¶
Represent a deployment of MongoDB servers.
See also
This module is compatible with both the synchronous and asynchronous PyMongo APIs.
- class pymongo.topology_description.TopologyDescription¶
Representation of a deployment of MongoDB servers.
- Parameters:
topology_type (int) – initial type
server_descriptions (dict[_Address, ServerDescription]) – dict of (address, ServerDescription) for all seeds
replica_set_name (str | None) – replica set name or None
max_set_version (int | None) – greatest setVersion seen from a primary, or None
max_election_id (ObjectId | None) – greatest electionId seen from a primary, or None
topology_settings (Any) – a TopologySettings
- apply_selector(selector, address=None, custom_selector=None, deprioritized_servers=None)¶
List of servers matching the provided selector(s).
- Parameters:
selector (Any) – a callable that takes a Selection as input and returns a Selection as output. For example, an instance of a read preference from
read_preferences.address (_Address | None) – A server address to select.
custom_selector (_ServerSelector | None) – A callable that augments server selection rules. Accepts a list of
ServerDescriptionobjects and return a list of server descriptions that should be considered suitable for the desired operation.deprioritized_servers (list[ServerDescription] | None)
- Return type:
list[ServerDescription]
Added in version 3.4.
- property candidate_servers: list[ServerDescription]¶
List of Servers excluding deprioritized servers.
- check_compatible()¶
Raise ConfigurationError if any server is incompatible.
A server is incompatible if its wire protocol version range does not overlap with PyMongo’s.
- Return type:
None
- property common_wire_version: int | None¶
Minimum of all servers’ max wire versions, or None.
- property has_known_servers: bool¶
Whether there are any Servers of types besides Unknown.
- has_readable_server(read_preference=Primary())¶
Check if this topology has any readable servers available.
The servers must match the given read preference.
- Parameters:
read_preference (_ServerMode) – an instance of a read preference from
read_preferences. Defaults toPRIMARY.- Return type:
bool
Note
When connected directly to a single server this method always returns
True.Added in version 3.4.
- has_writable_server()¶
Check if this topology has a writable server available.
Note
When connected directly to a single server this method always returns
True.Added in version 3.4.
- Return type:
bool
- property known_servers: list[ServerDescription]¶
List of Servers of types besides Unknown.
- property logical_session_timeout_minutes: int | None¶
Minimum logical session timeout, or None.
- property max_set_version: int | None¶
Greatest setVersion seen from a primary, or None.
- property readable_servers: list[ServerDescription]¶
List of readable Servers.
- property replica_set_name: str | None¶
The replica set name.
- reset()¶
Return a copy of this description, with all servers marked Unknown.
- Return type:
- reset_server(address)¶
Return a copy of this description, with one server marked Unknown.
- Parameters:
address (_Address)
- Return type:
- server_descriptions()¶
Return a dict of (address,
ServerDescription).- Return type:
dict[_Address, ServerDescription]
- property topology_type: int¶
The type of this topology.
- property topology_type_name: str¶
The topology type as a human readable string.
Added in version 3.4.