pool – Pool module for use with a MongoDB client.

  • class pymongo.pool.SocketInfo(sock, pool, address, id)
  • Store a socket with some metadata.

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
  • authenticate(credentials)
  • Log in to the server and store these credentials in authset.

Can raise ConnectionFailure or OperationFailure.

Parameters:

  1. - _credentials_: A MongoCredential.
  • checkauth(_all_credentials)
  • Update this socket’s authentication.

Log in or out to bring this socket’s credentials up to date withthose provided. Can raise ConnectionFailure or OperationFailure.

Parameters:

  1. - _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:

  1. - _dbname_: name of the database on which to run the command
  2. - _spec_: a command document as a dict, SON, or mapping object
  3. - _slave_ok_: whether to set the SlaveOkay wire protocol bit
  4. - _read_preference_: a read preference
  5. - _codec_options_: a CodecOptions instance
  6. - _check_: raise OperationFailure if there are errors
  7. - _allowable_errors_: errors to ignore if _check_ is True
  8. - _check_keys_: if True, check _spec_ for invalid keys
  9. - _read_concern_: The read concern for this command.
  10. - _write_concern_: The write concern for this command.
  11. - _parse_write_concern_error_: Whether to parse the<code>writeConcernError</code> field in the command response.
  12. - _collation_: The collation for this command.
  13. - _session_: optional ClientSession instance.
  14. - _client_: optional MongoClient for gossipping $clusterTime.
  15. - _retryable_write_: True if this command is a retryable write.
  16. - _publish_events_: Should we publish events for this command?
  17. - _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:

  1. - _request_id_: an int.
  2. - _msg_: bytes, an OP_INSERT, OP_UPDATE, or OP_DELETE message,perhaps with a getlasterror command appended.
  3. - _max_doc_size_: size in bytes of the largest document in _msg_.
  4. - _with_last_error_: True if a getlasterror command is appended.
  • receivemessage(_request_id)
  • Receive a raw BSON message or raise ConnectionFailure.

If any exception is raised, the socket is closed.

  • sendcluster_time(_command, session, client)
  • Add cluster time for MongoDB >= 3.6.

  • sendmessage(_message, max_doc_size)

  • Send a raw BSON message or raise ConnectionFailure.

If a network exception is raised, the socket is closed.

  • validatesession(_client, session)
  • Validate this session before use with client.

Raises error if this session is logged in as a different user orthe client is not the one that created the session.

  • writecommand(_request_id, msg)
  • Send “insert” etc. command, returning response as a dict.

Can raise ConnectionFailure or OperationFailure.

Parameters:

  1. - _request_id_: an int.
  2. - _msg_: bytes, the command message.