pool
– Pool module for use with a MongoDB client.
Store a socket with some metadata.
add_server_api
(command)Add server_api parameters.
authenticate
(credentials)Log in to the server and store these credentials in authset.
Can raise ConnectionFailure or OperationFailure.
Parameters: - credentials: A MongoCredential.
(all_credentials)
Update this socket’s authentication.
Log in or out to bring this socket’s credentials up to date with those provided. Can raise ConnectionFailure or OperationFailure.
close_socket
(reason)command
(dbname, spec, secondary_ok=False, read_preference=Primary(), codec_options=CodecOptions(document_class=dict, tz_aware=False, uuid_representation=UuidRepresentation.PYTHON_LEGACY, unicode_decode_error_handler=’strict’, tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None)), check=True, allowable_errors=None, check_keys=False, read_concern=None, write_concern=None, parse_write_concern_error=False, collation=None, session=None, client=None, retryable_write=False, publish_events=True, user_fields=None, exhaust_allowed=False)Execute a command or raise an error.
Parameters: - dbname: name of the database on which to run the command
- spec: a command document as a dict, SON, or mapping object
- read_preference: a read preference
- codec_options: a CodecOptions instance
- check: raise OperationFailure if there are errors
- allowable_errors: errors to ignore if check is True
- check_keys: if True, check spec for invalid keys
- read_concern: The read concern for this command.
- write_concern: The write concern for this command.
- parse_write_concern_error: Whether to parse the
writeConcernError
field in the command response. - collation: The collation for this command.
- session: optional ClientSession instance.
- client: optional MongoClient for gossipping $clusterTime.
- retryable_write: True if this command is a retryable write.
- publish_events: Should we publish events for this command?
idle_time_seconds
()Seconds since this socket was last checked into its pool.
(request_id, msg, max_doc_size, with_last_error)
Send OP_INSERT, etc., optionally returning response as a dict.
Can raise ConnectionFailure or OperationFailure.
receive_message
(request_id)Receive a raw BSON message or raise ConnectionFailure.
If any exception is raised, the socket is closed.
-
Add cluster time for MongoDB >= 3.6.
send_message
(message, max_doc_size)Send a raw BSON message or raise ConnectionFailure.
If a network exception is raised, the socket is closed.
socket_closed
()Return True if we know socket has been closed, False otherwise.
(client, session)
Validate this session before use with client.
Raises error if this session is logged in as a different user or the client is not the one that created the session.
write_command
(request_id, msg)Can raise ConnectionFailure or OperationFailure.
Parameters: - request_id: an int.