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

Class Primary

pymongo/read_preferences.py:280–305  ·  view source on GitHub ↗

Primary read preference. * When directly connected to one mongod queries are allowed if the server is standalone or a replica set primary. * When connected to a mongos queries are sent to the primary of a shard. * When connected to a replica set queries are sent to the primary of

Source from the content-addressed store, hash-verified

278
279
280class Primary(_ServerMode):
281 """Primary read preference.
282
283 * When directly connected to one mongod queries are allowed if the server
284 is standalone or a replica set primary.
285 * When connected to a mongos queries are sent to the primary of a shard.
286 * When connected to a replica set queries are sent to the primary of
287 the replica set.
288 """
289
290 __slots__ = ()
291
292 def __init__(self) -> None:
293 super().__init__(_PRIMARY)
294
295 def __call__(self, selection: Selection) -> Selection:
296 """Apply this read preference to a Selection."""
297 return selection.primary_selection
298
299 def __repr__(self) -> str:
300 return "Primary()"
301
302 def __eq__(self, other: Any) -> bool:
303 if isinstance(other, _ServerMode):
304 return other.mode == _PRIMARY
305 return NotImplemented
306
307
308class PrimaryPreferred(_ServerMode):

Calls

no outgoing calls