pool – Pool module for use with a MongoDB client.
Parameters:
- sock: a raw socket object
- pool: a Pool instance
- address: the server’s (host, port)
- id: the id of this socket in it’s pool
Can raise ConnectionFailure or OperationFailure.
Parameters:
- _credentials_: A MongoCredential.
Log in or out to bring this socket’s credentials up to date withthose provided. Can raise ConnectionFailure or OperationFailure.
Parameters:
- _all_credentials_: dict, maps auth source to MongoCredential.
closesocket
(_reason)Close this connection with a reason.
command
(dbname, spec, slave_ok=False, read_preference=Primary(), codec_options=CodecOptions(document_class=dict, tz_aware=False, uuid_representation=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)- 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
- _slave_ok_: whether to set the SlaveOkay wire protocol bit
- _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<code>writeConcernError</code> 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?
- _user_fields_ (optional): Response fields that should be decodedusing the TypeDecoders from codec_options, passed tobson._decode_all_selective.
idle_time_seconds
()Seconds since this socket was last checked into its pool.
legacywrite
(_request_id, msg, max_doc_size, with_last_error)- Send OP_INSERT, etc., optionally returning response as a dict.
Can raise ConnectionFailure or OperationFailure.
Parameters:
- _request_id_: an int.
- _msg_: bytes, an OP_INSERT, OP_UPDATE, or OP_DELETE message,perhaps with a getlasterror command appended.
- _max_doc_size_: size in bytes of the largest document in _msg_.
- _with_last_error_: True if a getlasterror command is appended.
If any exception is raised, the socket is closed.
sendcluster_time
(_command, session, client)Add cluster time for MongoDB >= 3.6.
- Send a raw BSON message or raise ConnectionFailure.
If a network exception is raised, the socket is closed.
Raises error if this session is logged in as a different user orthe client is not the one that created the session.
Can raise ConnectionFailure or OperationFailure.
Parameters:
- _request_id_: an int.
- _msg_: bytes, the command message.