sdkagent

mongo-python-driver API reference

400 public APIs from mongo-python-driver (mongodb/mongo-python-driver) — 112 classes, 56 functions, 232 methods. Signatures extracted by static analysis of the actual source.

Repository: mongodb/mongo-python-driver

KindCount
Classes112
Functions56
Methods232

API list

class_setup.custom_build_ext
Allow C extension building to fail.
classbson.BSON
BSON (Binary JSON) data.
methodbson.BSON.decode(codec_options:CodecOptions[Any]=DEFAULT_CODEC_OPTIONS) -> dict[str, Any]
Decode this BSON data.
methodbson.BSON.encode(document:Mapping[str, Any], check_keys:bool=False, codec_options:CodecOptions[Any]=DEFAULT_CODEC_OPTIONS) -> BSON
Encode a document to a new :class:`BSON` instance.
classbson.binary.Binary
Representation of BSON binary data.
methodbson.binary.Binary.as_uuid(uuid_representation:int=UuidRepresentation.STANDARD) -> UUID
Create a Python UUID from this BSON Binary object.
methodbson.binary.Binary.from_uuid(uuid:UUID, uuid_representation:int=UuidRepresentation.STANDARD) -> Binary
Create a BSON Binary object from a Python UUID.
methodbson.binary.Binary.subtype() -> int
Subtype of this binary data.
classbson.binary.BinaryVectorDtype
Datatypes of vector subtype.
classbson.code.Code
BSON's JavaScript code type.
methodbson.code.Code.scope() -> Optional[Mapping[str, Any]]
Scope dictionary for this instance or ``None``.
classbson.codec_options.DatetimeConversion
Options for decoding BSON datetimes.
methodbson.codec_options.TypeRegistry.codecs() -> list[TypeEncoder | TypeDecoder | TypeCodec]
The list of type codecs in this registry.
methodbson.codec_options.TypeRegistry.fallback_encoder() -> Optional[_Fallback]
The fallback encoder in this registry.
classbson.datetime_ms.DatetimeMS
Represents a BSON UTC datetime.
classbson.dbref.DBRef
A reference to a document stored in MongoDB.
methodbson.dbref.DBRef.as_doc() -> SON[str, Any]
Get the SON document representation of this DBRef.
methodbson.dbref.DBRef.collection() -> str
Get the name of this DBRef's collection.
methodbson.dbref.DBRef.database() -> Optional[str]
Get the name of this DBRef's database.
methodbson.dbref.DBRef.id() -> Any
Get this DBRef's _id.
funcbson.encode(document:Mapping[str, Any], check_keys:bool=False, codec_options:CodecOptions[Any]=DEFAULT_CODEC_OPTIONS) -> bytes
Encode a document to BSON.
classbson.errors.BSONError
Base class for all BSON exceptions.
classbson.errors.InvalidId
Raised when trying to create an ObjectId from invalid data.
funcbson.has_c() -> bool
Is the C extension installed?
classbson.int64.Int64
Representation of the BSON int64 type.
funcbson.is_valid(bson:bytes) -> bool
Check that the given string represents valid :class:`BSON` data.
funcbson.json_util.dumps(obj:Any, *args:Any, **kwargs:Any) -> str
Helper function that wraps :func:`json.dumps`.
funcbson.json_util.get_size(obj:Any, max_size:int, current_size:int=0) -> int
Recursively finds size of objects
funcbson.json_util.loads(s:Union[str, bytes, bytearray], *args:Any, **kwargs:Any) -> Any
Helper function that wraps :func:`json.loads`.
classbson.max_key.MaxKey
MongoDB internal MaxKey type.
classbson.min_key.MinKey
MongoDB internal MinKey type.
classbson.objectid.ObjectId
A MongoDB ObjectId.
methodbson.objectid.ObjectId.binary() -> bytes
12-byte binary representation of this ObjectId.
methodbson.objectid.ObjectId.is_valid(oid:Any) -> bool
Checks if a `oid` string is valid or not.
classbson.regex.Regex
BSON regular expression data.
methodbson.regex.Regex.from_native(regex:Pattern[_T]) -> Regex[_T]
Convert a Python regular expression into a ``Regex`` instance.
classbson.son.SON
SON data.
classbson.timestamp.Timestamp
MongoDB internal timestamps used in the opLog.
methodbson.timestamp.Timestamp.inc() -> int
Get the inc portion of this :class:`Timestamp`.
methodbson.timestamp.Timestamp.time() -> int
Get the time portion of this :class:`Timestamp`.
classbson.tz_util.FixedOffset
Fixed offset timezone, in minutes east from UTC.
classgridfs.asynchronous.grid_file.AsyncGridFS
An instance of GridFS on top of a single Database.
methodgridfs.asynchronous.grid_file.AsyncGridFS.delete(file_id:Any, session:Optional[AsyncClientSession]=None) -> None
Delete a file from GridFS by ``"_id"``.
methodgridfs.asynchronous.grid_file.AsyncGridFS.find(*args:Any, **kwargs:Any) -> AsyncGridOutCursor
Query GridFS for files.
methodgridfs.asynchronous.grid_file.AsyncGridFS.find_one(filter:Optional[Any]=None, session:Optional[AsyncClientSession]=None, *args:Any, **kwargs:Any) -> Optional[AsyncGridOut]
Get a single file from gridfs.
methodgridfs.asynchronous.grid_file.AsyncGridFS.get(file_id:Any, session:Optional[AsyncClientSession]=None) -> AsyncGridOut
Get a file from GridFS by ``"_id"``.
methodgridfs.asynchronous.grid_file.AsyncGridFS.new_file(**kwargs:Any) -> AsyncGridIn
Create a new file in GridFS.
methodgridfs.asynchronous.grid_file.AsyncGridFS.put(data:Any, **kwargs:Any) -> Any
Put data in GridFS as a new file.
classgridfs.asynchronous.grid_file.AsyncGridFSBucket
An instance of GridFS on top of a single Database.
classgridfs.asynchronous.grid_file.AsyncGridIn
Class to write data to GridFS.
methodgridfs.asynchronous.grid_file.AsyncGridIn.close() -> None
Flush the file and close it.
methodgridfs.asynchronous.grid_file.AsyncGridIn.closed() -> bool
Is this file closed?
methodgridfs.asynchronous.grid_file.AsyncGridIn.write(data:Any) -> None
Write data to the file.
methodgridfs.asynchronous.grid_file.AsyncGridIn.writelines(sequence:Iterable[Any]) -> None
Write a sequence of strings to the file.
classgridfs.asynchronous.grid_file.AsyncGridOut
Class to read data out of GridFS.
methodgridfs.asynchronous.grid_file.AsyncGridOut.close() -> None
Make GridOut more generically file-like.
methodgridfs.asynchronous.grid_file.AsyncGridOut.readchunk() -> bytes
Reads a chunk at a time.
methodgridfs.asynchronous.grid_file.AsyncGridOut.readline(size:int=-1) -> bytes
Read one line or up to `size` bytes from the file.
methodgridfs.asynchronous.grid_file.AsyncGridOut.readlines(size:int=-1) -> list[bytes]
Read one line or up to `size` bytes from the file.
methodgridfs.asynchronous.grid_file.AsyncGridOut.seek(pos:int, whence:int=_SEEK_SET) -> int
Set the current position of this file.
methodgridfs.asynchronous.grid_file.AsyncGridOut.tell() -> int
Return the current position of this file.
classgridfs.errors.CorruptGridFile
Raised when a file in :class:`~gridfs.GridFS` is malformed.
classgridfs.errors.FileExists
Raised when trying to create a file that already exists.
classgridfs.errors.GridFSError
Base class for all GridFS exceptions.
classgridfs.errors.NoFile
Raised when trying to read from a non-existent file.
classgridfs.synchronous.grid_file.GridFS
An instance of GridFS on top of a single Database.
methodgridfs.synchronous.grid_file.GridFS.delete(file_id:Any, session:Optional[ClientSession]=None) -> None
Delete a file from GridFS by ``"_id"``.
methodgridfs.synchronous.grid_file.GridFS.find(*args:Any, **kwargs:Any) -> GridOutCursor
Query GridFS for files.
methodgridfs.synchronous.grid_file.GridFS.find_one(filter:Optional[Any]=None, session:Optional[ClientSession]=None, *args:Any, **kwargs:Any) -> Optional[GridOut]
Get a single file from gridfs.
methodgridfs.synchronous.grid_file.GridFS.get(file_id:Any, session:Optional[ClientSession]=None) -> GridOut
Get a file from GridFS by ``"_id"``.
methodgridfs.synchronous.grid_file.GridFS.new_file(**kwargs:Any) -> GridIn
Create a new file in GridFS.
methodgridfs.synchronous.grid_file.GridFS.put(data:Any, **kwargs:Any) -> Any
Put data in GridFS as a new file.
classgridfs.synchronous.grid_file.GridFSBucket
An instance of GridFS on top of a single Database.
classgridfs.synchronous.grid_file.GridIn
Class to write data to GridFS.
methodgridfs.synchronous.grid_file.GridIn.close() -> None
Flush the file and close it.
methodgridfs.synchronous.grid_file.GridIn.closed() -> bool
Is this file closed?
methodgridfs.synchronous.grid_file.GridIn.write(data:Any) -> None
Write data to the file.
methodgridfs.synchronous.grid_file.GridIn.writelines(sequence:Iterable[Any]) -> None
Write a sequence of strings to the file.
classgridfs.synchronous.grid_file.GridOut
Class to read data out of GridFS.
methodgridfs.synchronous.grid_file.GridOut.close() -> None
Make GridOut more generically file-like.
methodgridfs.synchronous.grid_file.GridOut.readchunk() -> bytes
Reads a chunk at a time.
methodgridfs.synchronous.grid_file.GridOut.readline(size:int=-1) -> bytes
Read one line or up to `size` bytes from the file.
methodgridfs.synchronous.grid_file.GridOut.readlines(size:int=-1) -> list[bytes]
Read one line or up to `size` bytes from the file.
methodgridfs.synchronous.grid_file.GridOut.seek(pos:int, whence:int=_SEEK_SET) -> int
Set the current position of this file.
methodgridfs.synchronous.grid_file.GridOut.tell() -> int
Return the current position of this file.
classgridfs.synchronous.grid_file.GridOutChunkIterator
Iterates over a file's chunks using a single cursor.
classhatch_build.CustomHook
The pymongo build hook.
methodhatch_build.CustomHook.initialize(version, build_data)
Initialize the hook.
classpymongo._asyncio_lock.Condition
Asynchronous equivalent to threading.Condition.
methodpymongo._asyncio_lock.Condition.notify(n:int=1) -> None
By default, wake up one task waiting on this condition, if any.
methodpymongo._asyncio_lock.Condition.notify_all() -> None
Wake up all tasks waiting on this condition.
methodpymongo._asyncio_lock.Condition.wait() -> bool
Wait until notified.
methodpymongo._asyncio_lock.Condition.wait_for(predicate:Any) -> Coroutine[Any, Any, Any]
Wait until a predicate becomes true.
classpymongo._asyncio_lock.Lock
Primitive lock objects.
methodpymongo._asyncio_lock.Lock.acquire() -> bool
Acquire a lock.
methodpymongo._asyncio_lock.Lock.locked() -> bool
Return True if lock is acquired.
methodpymongo._asyncio_lock.Lock.release() -> None
Release a lock.
classpymongo._csot.MovingMinimum
Tracks a minimum RTT within the last 10 RTT samples.
methodpymongo._csot.MovingMinimum.get() -> float
Get the min, or 0.0 if there aren't enough samples yet.
funcpymongo._csot.apply(func:F) -> F
Apply the client's timeoutMS to this operation.
funcpymongo._csot.apply_write_concern(cmd:MutableMapping[str, Any], write_concern:Optional[WriteConcern]) -> None
Apply the given write concern to a command.
funcpymongo._csot.clamp_remaining(max_timeout:float) -> float
Return the remaining timeout clamped to a max value.
funcpymongo._telemetry.log_command_retry(topology_id:Optional[ObjectId], command_name:str, operation_id:Optional[int], attempt_number:int, is_write:bool) -> None
Emit a command-retry log entry.
funcpymongo.asynchronous.auth.authenticate(credentials:MongoCredential, conn:AsyncConnection, reauthenticate:bool=False) -> None
Authenticate connection.
classpymongo.asynchronous.client_session.AsyncClientSession
A session for ordering sequential operations.
methodpymongo.asynchronous.client_session.AsyncClientSession.abort_transaction() -> None
Abort a multi-statement transaction.
methodpymongo.asynchronous.client_session.AsyncClientSession.advance_cluster_time(cluster_time:Mapping[str, Any]) -> None
Update the cluster time for this session.
methodpymongo.asynchronous.client_session.AsyncClientSession.advance_operation_time(operation_time:Timestamp) -> None
Update the operation time for this session.
methodpymongo.asynchronous.client_session.AsyncClientSession.commit_transaction() -> None
Commit a multi-statement transaction.
methodpymongo.asynchronous.client_session.AsyncClientSession.end_session() -> None
Finish this session.
methodpymongo.asynchronous.client_session.AsyncClientSession.has_ended() -> bool
True if this session is finished.
classpymongo.asynchronous.client_session.SessionOptions
Options for a new :class:`AsyncClientSession`.
methodpymongo.asynchronous.client_session.SessionOptions.causal_consistency() -> bool
Whether causal consistency is configured.
methodpymongo.asynchronous.client_session.SessionOptions.snapshot() -> Optional[bool]
Whether snapshot reads are configured.
classpymongo.asynchronous.collection.AsyncCollection
An asynchronous Mongo collection.
methodpymongo.asynchronous.collection.AsyncCollection.create_index(keys:_IndexKeyHint, session:Optional[AsyncClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> str
Creates an index on this collection.
methodpymongo.asynchronous.collection.AsyncCollection.drop_indexes(session:Optional[AsyncClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> None
Drops all indexes on this collection.
methodpymongo.asynchronous.collection.AsyncCollection.drop_search_index(name:str, session:Optional[AsyncClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> None
Delete a search index by index name.
methodpymongo.asynchronous.collection.AsyncCollection.find(*args:Any, **kwargs:Any) -> AsyncCursor[_DocumentType]
Query the database.
methodpymongo.asynchronous.collection.AsyncCollection.find_one(filter:Optional[Any]=None, *args:Any, **kwargs:Any) -> Optional[_DocumentType]
Get a single document from the database.
methodpymongo.asynchronous.collection.AsyncCollection.full_name() -> str
The full name of this :class:`AsyncCollection`.
methodpymongo.asynchronous.collection.AsyncCollection.name() -> str
The name of this :class:`AsyncCollection`.
methodpymongo.asynchronous.collection.AsyncCollection.options(session:Optional[AsyncClientSession]=None, comment:Optional[Any]=None) -> MutableMapping[str, Any]
Get the options set on this collection.
methodpymongo.asynchronous.collection.AsyncCollection.rename(new_name:str, session:Optional[AsyncClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> MutableMapping[str, Any]
Rename this collection.
methodpymongo.asynchronous.cursor.AsyncCursor.add_option(mask:int) -> AsyncCursor[_DocumentType]
Set arbitrary query flags using a bitmask.
methodpymongo.asynchronous.cursor.AsyncCursor.batch_size(batch_size:int) -> AsyncCursor[_DocumentType]
Limits the number of documents returned in one batch.
methodpymongo.asynchronous.cursor.AsyncCursor.clone() -> AsyncCursor[_DocumentType]
Get a clone of this cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.comment(comment:Any) -> AsyncCursor[_DocumentType]
Adds a 'comment' to the cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.explain() -> _DocumentType
Returns an explain plan record for this cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.limit(limit:int) -> AsyncCursor[_DocumentType]
Limits the number of results to be returned by this cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.max_time_ms(max_time_ms:Optional[int]) -> AsyncCursor[_DocumentType]
Specifies a time limit for a query operation.
methodpymongo.asynchronous.cursor.AsyncCursor.min(spec:_Sort) -> AsyncCursor[_DocumentType]
Adds ``min`` operator that specifies lower bound for specific index.
methodpymongo.asynchronous.cursor.AsyncCursor.next() -> _DocumentType
Advance the cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.remove_option(mask:int) -> AsyncCursor[_DocumentType]
Unset arbitrary query flags using a bitmask.
methodpymongo.asynchronous.cursor.AsyncCursor.retrieved() -> int
The number of documents retrieved so far.
methodpymongo.asynchronous.cursor.AsyncCursor.rewind() -> AsyncCursor[_DocumentType]
Rewind this cursor to its unevaluated state.
methodpymongo.asynchronous.cursor.AsyncCursor.skip(skip:int) -> AsyncCursor[_DocumentType]
Skips the first `skip` results of this cursor.
methodpymongo.asynchronous.cursor.AsyncCursor.sort(key_or_list:_Hint, direction:Optional[Union[int, str]]=None) -> AsyncCursor[_DocumentType]
Sorts this cursor's results.
methodpymongo.asynchronous.cursor.AsyncCursor.where(code:Union[str, Code]) -> AsyncCursor[_DocumentType]
Adds a `$where`_ clause to this query.
methodpymongo.asynchronous.database.AsyncDatabase.name() -> str
The name of this :class:`AsyncDatabase`.
classpymongo.asynchronous.encryption.AsyncClientEncryption
Explicit client-side field level encryption.
methodpymongo.asynchronous.encryption.AsyncClientEncryption.close() -> None
Release resources.
methodpymongo.asynchronous.encryption.AsyncClientEncryption.decrypt(value:Binary) -> Any
Decrypt an encrypted value.
methodpymongo.asynchronous.encryption.AsyncClientEncryption.get_key(id:Binary) -> Optional[RawBSONDocument]
Get a data key by id.
methodpymongo.asynchronous.encryption.AsyncClientEncryption.get_keys() -> AsyncCursor[RawBSONDocument]
Get all of the data keys.
methodpymongo.asynchronous.monitor.Monitor.cancel_check() -> None
Cancel any concurrent hello check.
classpymongo.asynchronous.pool.AsyncConnection
Store a connection with some metadata.
methodpymongo.asynchronous.pool.AsyncConnection.add_server_api(command:MutableMapping[str, Any]) -> None
Add server_api parameters.
methodpymongo.asynchronous.pool.AsyncConnection.authenticate(reauthenticate:bool=False) -> None
Authenticate to the server if needed.
methodpymongo.asynchronous.pool.AsyncConnection.close_conn(reason:Optional[str]) -> None
Close this connection with a reason.
methodpymongo.asynchronous.pool.AsyncConnection.receive_message(request_id:Optional[int]) -> _OpMsg
Receive a raw BSON message or raise ConnectionFailure.
methodpymongo.asynchronous.pool.AsyncConnection.send_cluster_time(command:MutableMapping[str, Any], session:Optional[AsyncClientSession], client:Optional[AsyncMongoClient[Any]]) -> None
Add $clusterTime.
methodpymongo.asynchronous.pool.AsyncConnection.send_message(message:bytes, max_doc_size:int) -> None
Send a raw BSON message or raise ConnectionFailure.
methodpymongo.asynchronous.pool.Pool.checkout(handler:Optional[_ClientCheckout]=None) -> _PoolCheckout
Get a connection from the pool.
methodpymongo.asynchronous.pool.Pool.connect(handler:Optional[_ClientCheckout]=None) -> AsyncConnection
Connect to Mongo and return a new AsyncConnection.
methodpymongo.asynchronous.server.Server.close() -> None
Clear the connection pool and stop the monitor.
methodpymongo.asynchronous.server.Server.open() -> None
Start monitoring, or restart after a fork.
methodpymongo.asynchronous.server.Server.request_check() -> None
Check the server's state soon.
methodpymongo.asynchronous.server.Server.reset(service_id:Optional[ObjectId]=None) -> None
Clear the connection pool.
classpymongo.asynchronous.topology.Topology
Monitor a topology of one or more servers.
methodpymongo.asynchronous.topology.Topology.close() -> None
Clear pools and terminate monitors.
methodpymongo.asynchronous.topology.Topology.get_arbiters() -> set[_Address]
Return set of arbiter addresses.
methodpymongo.asynchronous.topology.Topology.get_primary() -> Optional[_Address]
Return primary's address or None.
methodpymongo.asynchronous.topology.Topology.get_secondaries() -> set[_Address]
Return set of secondary addresses.
methodpymongo.asynchronous.topology.Topology.get_server_by_address(address:_Address) -> Optional[Server]
Get a Server or None.
methodpymongo.asynchronous.topology.Topology.handle_error(address:_Address, err_ctx:_ErrorContext) -> None
Handle an application error.
methodpymongo.asynchronous.topology.Topology.open() -> None
Start monitoring, or restart after a fork.
methodpymongo.asynchronous.topology.Topology.pop_all_sessions() -> list[_ServerSession]
Pop all session ids from the pool.
classpymongo.auth_oidc_shared.OIDCCallback
A base class for defining OIDC callbacks.
methodpymongo.auth_oidc_shared.OIDCCallback.fetch(context:OIDCCallbackContext) -> OIDCCallbackResult
Convert the given BSON value into our own type.
methodpymongo.client_options.ClientOptions.heartbeat_frequency() -> int
The monitoring frequency in seconds.
methodpymongo.client_options.ClientOptions.local_threshold_ms() -> int
The local threshold for this instance.
methodpymongo.client_options.ClientOptions.max_adaptive_retries() -> int
The configured maxAdaptiveRetries option.
methodpymongo.client_options.ClientOptions.pool_options() -> PoolOptions
A :class:`~pymongo.pool.PoolOptions` instance.
methodpymongo.client_options.ClientOptions.read_preference() -> _ServerMode
A read preference instance.
methodpymongo.client_options.ClientOptions.replica_set_name() -> Optional[str]
Replica set name or None.
methodpymongo.client_options.ClientOptions.server_monitoring_mode() -> str
The configured serverMonitoringMode option.
methodpymongo.collation.Collation.document() -> dict[str, Any]
The document representation of this collation.
classpymongo.common.Version
A class that can be used to compare version strings.
funcpymongo.common.clean_node(node:str) -> tuple[str, int]
Split and normalize a node name from a hello response.
funcpymongo.common.has_c() -> bool
Is the C extension installed?
funcpymongo.common.partition_node(node:str) -> tuple[str, int]
Split a host:port string into (host, int(port)) pair.
funcpymongo.common.raise_config_error(key:str, suggestions:Optional[list[str]]=None) -> NoReturn
Raise ConfigurationError with the given key name.
funcpymongo.common.validate(option:str, value:Any) -> tuple[str, Any]
Generic validation function.
funcpymongo.common.validate_appname_or_none(option:str, value:Any) -> Optional[str]
Validate the appname option.
funcpymongo.common.validate_auth_mechanism(option:str, value:Any) -> str
Validate the authMechanism URI option.
funcpymongo.common.validate_auth_mechanism_properties(option:str, value:Any) -> dict[str, Union[bool, str]]
Validate authMechanismProperties.
funcpymongo.common.validate_auto_encryption_opts_or_none(option:Any, value:Any) -> Optional[Any]
Validate the driver keyword arg.
funcpymongo.common.validate_boolean_or_string(option:str, value:Any) -> bool
Validates that value is True, False, 'true', or 'false'.
funcpymongo.common.validate_datetime_conversion(option:Any, value:Any) -> Optional[DatetimeConversion]
Validate a DatetimeConversion string.
funcpymongo.common.validate_document_class(option:str, value:Any) -> Union[type[MutableMapping[str, Any]], type[RawBSONDocument]]
Validate the document_class option.
funcpymongo.common.validate_driver_or_none(option:Any, value:Any) -> Optional[DriverInfo]
Validate the driver keyword arg.
funcpymongo.common.validate_integer(option:str, value:Any) -> int
Validates that 'value' is an integer (or basestring representation).
funcpymongo.common.validate_is_callable_or_none(option:Any, value:Any) -> Optional[Callable[..., Any]]
Validates that 'value' is a callable.
funcpymongo.common.validate_is_mapping(option:str, value:Any) -> None
Validate the type of method arguments that expect a document.
funcpymongo.common.validate_list(option:str, value:Any) -> list[Any]
Validates that 'value' is a list.
funcpymongo.common.validate_list_or_mapping(option:Any, value:Any) -> None
Validates that 'value' is a list or a document.
funcpymongo.common.validate_list_or_none(option:Any, value:Any) -> Optional[list[Any]]
Validates that 'value' is a list or None.
funcpymongo.common.validate_non_negative_int_or_basestring(option:Any, value:Any) -> Union[int, str]
Validates that 'value' is an integer or string.
funcpymongo.common.validate_non_negative_integer(option:str, value:Any) -> int
Validate that 'value' is a positive integer or 0.
funcpymongo.common.validate_ok_for_replace(replacement:Mapping[str, Any]) -> None
Validate a replacement document.
funcpymongo.common.validate_ok_for_update(update:Any) -> None
Validate an update document.
funcpymongo.common.validate_read_preference(dummy:Any, value:Any) -> _ServerMode
Validate a read preference.
funcpymongo.common.validate_read_preference_mode(dummy:Any, value:Any) -> _ServerMode
Validate read preference mode for a MongoClient.
funcpymongo.common.validate_read_preference_tags(name:str, value:Any) -> list[dict[str, str]]
Parse readPreferenceTags if passed as a client kwarg.
funcpymongo.common.validate_readable(option:str, value:Any) -> Optional[str]
Validates that 'value' is file-like and readable.
funcpymongo.common.validate_server_api_or_none(option:Any, value:Any) -> Optional[ServerApi]
Validate the server_api keyword arg.
funcpymongo.common.validate_server_monitoring_mode(option:str, value:str) -> str
Validate the serverMonitoringMode option.
funcpymongo.common.validate_string(option:str, value:Any) -> str
Validates that 'value' is an instance of `str`.
funcpymongo.common.validate_type_registry(option:Any, value:Any) -> Optional[TypeRegistry]
Validate the type_registry option.
funcpymongo.common.validate_tzinfo(dummy:Any, value:Any) -> Optional[datetime.tzinfo]
Validate the tzinfo option
funcpymongo.common.validate_uuid_representation(dummy:Any, value:Any) -> int
Validate the uuid representation option selected in the URI.
classpymongo.driver_info.DriverInfo
Info about a driver wrapping PyMongo.
classpymongo.encryption_options.PrefixOpts
**BETA** Options for prefix text queries.
classpymongo.encryption_options.SubstringOpts
**BETA** Options for substring text queries.
classpymongo.encryption_options.SuffixOpts
**BETA** Options for suffix text queries.
classpymongo.errors.BulkWriteError
Exception class for bulk write errors.
classpymongo.errors.ClientBulkWriteException
Exception class for client-level bulk write errors.
classpymongo.errors.CollectionInvalid
Raised when collection validation fails.
classpymongo.errors.ConfigurationError
Raised when something is incorrectly configured.
classpymongo.errors.EncryptionError
Raised when encryption or decryption fails.
classpymongo.errors.InvalidName
Raised when an invalid name is used.
classpymongo.errors.InvalidOperation
Raised when a client attempts to perform an invalid operation.
classpymongo.errors.InvalidURI
Raised when trying to parse an invalid mongodb URI.
classpymongo.errors.NotPrimaryError
The server responded "not primary" or "node is recovering".
classpymongo.errors.OperationFailure
Raised when a database operation fails.
methodpymongo.errors.OperationFailure.code() -> Optional[int]
The error code returned by the server, if any.
classpymongo.errors.ProtocolError
Raised for failures related to the wire protocol.
classpymongo.errors.PyMongoError
Base class for all PyMongo exceptions.
methodpymongo.errors.PyMongoError.has_error_label(label:str) -> bool
Return True if this error contains the given label.
methodpymongo.errors.PyMongoError.timeout() -> bool
True if this error was caused by a timeout.
classpymongo.errors.WTimeoutError
Raised when a database operation times out (i.e.
classpymongo.errors.WriteConcernError
Base exception type for errors raised due to write concern.
classpymongo.event_loggers.CommandLogger
A simple listener that logs command events.
classpymongo.event_loggers.HeartbeatLogger
A simple listener that logs server heartbeat events.
classpymongo.event_loggers.ServerLogger
A simple listener that logs server discovery events.
classpymongo.event_loggers.TopologyLogger
A simple listener that logs server topology events.
classpymongo.hello.Hello
Parse a hello response from the server.
methodpymongo.hello.Hello.document() -> _DocumentType
The complete hello command response document.
methodpymongo.hello.Hello.replica_set_name() -> Optional[str]
Replica set name or None.
methodpymongo.hello.Hello.speculative_authenticate() -> Optional[Mapping[str, Any]]
The speculativeAuthenticate field.
methodpymongo.hello.Hello.tags() -> Mapping[str, Any]
Replica set member tags or empty dict.
funcpymongo.max_staleness_selectors.select(max_staleness:int, selection:Selection) -> Selection
Apply max_staleness, in seconds, to a Selection.
classpymongo.monitoring.CommandFailedEvent
Event published when a command fails.
methodpymongo.monitoring.CommandFailedEvent.duration_micros() -> int
The duration of this operation in microseconds.
methodpymongo.monitoring.CommandFailedEvent.failure() -> _DocumentOut
The server failure document for this operation.
classpymongo.monitoring.CommandListener
Abstract base class for command listeners.
methodpymongo.monitoring.CommandListener.failed(event:CommandFailedEvent) -> None
Abstract method to handle a `CommandFailedEvent`.
methodpymongo.monitoring.CommandListener.started(event:CommandStartedEvent) -> None
Abstract method to handle a `CommandStartedEvent`.
methodpymongo.monitoring.CommandListener.succeeded(event:CommandSucceededEvent) -> None
Abstract method to handle a `CommandSucceededEvent`.
classpymongo.monitoring.CommandStartedEvent
Event published when a command starts.
methodpymongo.monitoring.CommandStartedEvent.command() -> _DocumentOut
The command document.
classpymongo.monitoring.CommandSucceededEvent
Event published when a command succeeds.
methodpymongo.monitoring.CommandSucceededEvent.duration_micros() -> int
The duration of this operation in microseconds.
methodpymongo.monitoring.CommandSucceededEvent.reply() -> _DocumentOut
The server failure document for this operation.
classpymongo.monitoring.ConnectionClosedEvent
Published when a Connection is closed.
methodpymongo.monitoring.ConnectionClosedEvent.reason() -> str
A reason explaining why this connection was closed.
classpymongo.monitoring.ConnectionPoolListener
Abstract base class for connection pool listeners.
methodpymongo.monitoring.ConnectionPoolListener.pool_cleared(event:PoolClearedEvent) -> None
Abstract method to handle a `PoolClearedEvent`.
methodpymongo.monitoring.ConnectionPoolListener.pool_closed(event:PoolClosedEvent) -> None
Abstract method to handle a `PoolClosedEvent`.
methodpymongo.monitoring.ConnectionPoolListener.pool_created(event:PoolCreatedEvent) -> None
Abstract method to handle a :class:`PoolCreatedEvent`.
methodpymongo.monitoring.ConnectionPoolListener.pool_ready(event:PoolReadyEvent) -> None
Abstract method to handle a :class:`PoolReadyEvent`.
classpymongo.monitoring.PoolClearedEvent
Published when a Connection Pool is cleared.
methodpymongo.monitoring.PoolClearedEvent.service_id() -> Optional[ObjectId]
Connections with this service_id are cleared.
classpymongo.monitoring.PoolClosedEvent
Published when a Connection Pool is closed.
classpymongo.monitoring.PoolCreatedEvent
Published when a Connection Pool is created.
classpymongo.monitoring.PoolReadyEvent
Published when a Connection Pool is marked ready.
classpymongo.monitoring.ServerClosedEvent
Published when server is closed.
classpymongo.monitoring.ServerDescriptionChangedEvent
Published when server description changes.
classpymongo.monitoring.ServerHeartbeatListener
Abstract base class for server heartbeat listeners.
classpymongo.monitoring.ServerHeartbeatStartedEvent
Published when a heartbeat is started.
classpymongo.monitoring.ServerHeartbeatSucceededEvent
Fired when the server heartbeat succeeds.
methodpymongo.monitoring.ServerHeartbeatSucceededEvent.awaited() -> bool
Whether the heartbeat was awaited.
methodpymongo.monitoring.ServerHeartbeatSucceededEvent.duration() -> float
The duration of this heartbeat in microseconds.
classpymongo.monitoring.ServerListener
Abstract base class for server listeners.
methodpymongo.monitoring.ServerListener.closed(event:ServerClosedEvent) -> None
Abstract method to handle a `ServerClosedEvent`.
methodpymongo.monitoring.ServerListener.opened(event:ServerOpeningEvent) -> None
Abstract method to handle a `ServerOpeningEvent`.
classpymongo.monitoring.ServerOpeningEvent
Published when server is initialized.
classpymongo.monitoring.TopologyClosedEvent
Published when the topology is closed.
classpymongo.monitoring.TopologyDescriptionChangedEvent
Published when the topology description changes.
classpymongo.monitoring.TopologyEvent
Base class for topology description events.
classpymongo.monitoring.TopologyListener
Abstract base class for topology monitoring listeners.
methodpymongo.monitoring.TopologyListener.closed(event:TopologyClosedEvent) -> None
Abstract method to handle a `TopologyClosedEvent`.
methodpymongo.monitoring.TopologyListener.opened(event:TopologyOpenedEvent) -> None
Abstract method to handle a `TopologyOpenedEvent`.
classpymongo.monitoring.TopologyOpenedEvent
Published when the topology is initialized.
funcpymongo.monitoring.register(listener:_EventListener) -> None
Register a global event listener.
funcpymongo.network_layer.receive_message(conn:Connection, request_id:Optional[int], max_message_size:int=MAX_MESSAGE_SIZE) -> _OpMsg
Receive a raw BSON message or raise socket.error.
classpymongo.operations.DeleteMany
Represents a delete_many operation.
classpymongo.operations.DeleteOne
Represents a delete_one operation.
classpymongo.operations.IndexModel
Represents an index to create.
classpymongo.operations.InsertOne
Represents an insert_one operation.
classpymongo.operations.ReplaceOne
Represents a replace_one operation.
classpymongo.operations.SearchIndexModel
Represents a search index to create.
methodpymongo.operations.SearchIndexModel.document() -> Mapping[str, Any]
The document for this index.
classpymongo.operations.UpdateMany
Represents an update_many operation.
classpymongo.operations.UpdateOne
Represents an update_one operation.
classpymongo.read_preferences.MovingAverage
Tracks an exponentially-weighted moving average.
classpymongo.read_preferences.Nearest
Nearest read preference.
classpymongo.read_preferences.Primary
Primary read preference.
classpymongo.read_preferences.PrimaryPreferred
PrimaryPreferred read preference.
classpymongo.read_preferences.Secondary
Secondary read preference.
classpymongo.read_preferences.SecondaryPreferred
SecondaryPreferred read preference.
funcpymongo.read_preferences.read_pref_mode_from_name(name:str) -> int
Get the read preference mode from mongos/uri name.
methodpymongo.response.Response.address() -> _Address
(host, port) of the source server.
methodpymongo.response.Response.data() -> _OpMsg
Server response's raw BSON bytes.
methodpymongo.response.Response.docs() -> Sequence[Mapping[str, Any]]
The decoded document(s).
methodpymongo.response.Response.duration() -> Optional[timedelta]
The duration of the operation.
methodpymongo.response.Response.from_command() -> bool
If the response is a result from a db command.
methodpymongo.response.Response.request_id() -> int
The request id of this operation.
methodpymongo.results.ClientBulkWriteResult.has_verbose_results() -> bool
Whether the returned results should be verbose.
methodpymongo.results.DeleteResult.deleted_count() -> int
The number of documents deleted.
methodpymongo.results.DeleteResult.raw_result() -> Mapping[str, Any]
The raw result document returned by the server.
methodpymongo.results.UpdateResult.did_upsert() -> bool
Whether an upsert took place.
methodpymongo.results.UpdateResult.matched_count() -> int
The number of documents matched for this update.
methodpymongo.results.UpdateResult.modified_count() -> int
The number of documents modified.
methodpymongo.results.UpdateResult.raw_result() -> Optional[Mapping[str, Any]]
The raw result document returned by the server.
funcpymongo.saslprep.saslprep(data:Any, prohibit_unassigned_code_points:Optional[bool]=True) -> Any
SASLprep dummy
classpymongo.server_api.ServerApi
MongoDB Stable API.
methodpymongo.server_api.ServerApi.deprecation_errors() -> Optional[bool]
The API deprecation errors setting.
methodpymongo.server_api.ServerApi.strict() -> Optional[bool]
The API strict mode setting.
methodpymongo.server_api.ServerApi.version() -> str
The API version setting.
classpymongo.server_description.ServerDescription
Immutable representation of one server.
methodpymongo.server_description.ServerDescription.address() -> _Address
The address (host, port) of this server.
methodpymongo.server_description.ServerDescription.min_round_trip_time() -> float
The min latency from the most recent samples.
methodpymongo.server_description.ServerDescription.replica_set_name() -> Optional[str]
Replica set name or None.
methodpymongo.server_description.ServerDescription.round_trip_time() -> Optional[float]
The current average latency or None.
methodpymongo.server_description.ServerDescription.server_type() -> int
The type of this server.
methodpymongo.server_description.ServerDescription.server_type_name() -> str
The server type as a human readable string.
classpymongo.server_selectors.Selection
Input or output of a server selector function.
funcpymongo.server_selectors.apply_single_tag_set(tag_set:TagSet, selection:Selection) -> Selection
All servers matching one tag set.
funcpymongo.server_selectors.apply_tag_sets(tag_sets:TagSets, selection:Selection) -> Selection
All servers match a list of tag sets.
funcpymongo.server_selectors.member_with_tags_server_selector(tag_sets:TagSets, selection:Selection) -> Selection
All near-enough members matching the tag sets.
funcpymongo.server_selectors.secondary_with_tags_server_selector(tag_sets:TagSets, selection:Selection) -> Selection
All near-enough secondaries matching the tag sets.
funcpymongo.server_selectors.writable_preferred_server_selector(selection:Selection) -> Selection
Like PrimaryPreferred but doesn't use tags or latency.
funcpymongo.synchronous.auth.authenticate(credentials:MongoCredential, conn:Connection, reauthenticate:bool=False) -> None
Authenticate connection.
classpymongo.synchronous.client_session.ClientSession
A session for ordering sequential operations.
methodpymongo.synchronous.client_session.ClientSession.abort_transaction() -> None
Abort a multi-statement transaction.
methodpymongo.synchronous.client_session.ClientSession.advance_cluster_time(cluster_time:Mapping[str, Any]) -> None
Update the cluster time for this session.
methodpymongo.synchronous.client_session.ClientSession.advance_operation_time(operation_time:Timestamp) -> None
Update the operation time for this session.
methodpymongo.synchronous.client_session.ClientSession.commit_transaction() -> None
Commit a multi-statement transaction.
methodpymongo.synchronous.client_session.ClientSession.end_session() -> None
Finish this session.
methodpymongo.synchronous.client_session.ClientSession.has_ended() -> bool
True if this session is finished.
classpymongo.synchronous.client_session.SessionOptions
Options for a new :class:`ClientSession`.
methodpymongo.synchronous.client_session.SessionOptions.causal_consistency() -> bool
Whether causal consistency is configured.
methodpymongo.synchronous.client_session.SessionOptions.snapshot() -> Optional[bool]
Whether snapshot reads are configured.
classpymongo.synchronous.collection.Collection
A Mongo collection.
methodpymongo.synchronous.collection.Collection.create_index(keys:_IndexKeyHint, session:Optional[ClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> str
Creates an index on this collection.
methodpymongo.synchronous.collection.Collection.drop_indexes(session:Optional[ClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> None
Drops all indexes on this collection.
methodpymongo.synchronous.collection.Collection.drop_search_index(name:str, session:Optional[ClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> None
Delete a search index by index name.
methodpymongo.synchronous.collection.Collection.find(*args:Any, **kwargs:Any) -> Cursor[_DocumentType]
Query the database.
methodpymongo.synchronous.collection.Collection.find_one(filter:Optional[Any]=None, *args:Any, **kwargs:Any) -> Optional[_DocumentType]
Get a single document from the database.
methodpymongo.synchronous.collection.Collection.full_name() -> str
The full name of this :class:`Collection`.
methodpymongo.synchronous.collection.Collection.name() -> str
The name of this :class:`Collection`.
methodpymongo.synchronous.collection.Collection.options(session:Optional[ClientSession]=None, comment:Optional[Any]=None) -> MutableMapping[str, Any]
Get the options set on this collection.
methodpymongo.synchronous.collection.Collection.rename(new_name:str, session:Optional[ClientSession]=None, comment:Optional[Any]=None, **kwargs:Any) -> MutableMapping[str, Any]
Rename this collection.
classpymongo.synchronous.command_cursor.CommandCursor
A cursor / iterator over command cursors.
methodpymongo.synchronous.command_cursor.CommandCursor.next() -> _DocumentType
Advance the cursor.
methodpymongo.synchronous.cursor.Cursor.add_option(mask:int) -> Cursor[_DocumentType]
Set arbitrary query flags using a bitmask.
methodpymongo.synchronous.cursor.Cursor.batch_size(batch_size:int) -> Cursor[_DocumentType]
Limits the number of documents returned in one batch.
methodpymongo.synchronous.cursor.Cursor.clone() -> Cursor[_DocumentType]
Get a clone of this cursor.
methodpymongo.synchronous.cursor.Cursor.comment(comment:Any) -> Cursor[_DocumentType]
Adds a 'comment' to the cursor.
methodpymongo.synchronous.cursor.Cursor.explain() -> _DocumentType
Returns an explain plan record for this cursor.
methodpymongo.synchronous.cursor.Cursor.limit(limit:int) -> Cursor[_DocumentType]
Limits the number of results to be returned by this cursor.
methodpymongo.synchronous.cursor.Cursor.max_time_ms(max_time_ms:Optional[int]) -> Cursor[_DocumentType]
Specifies a time limit for a query operation.
methodpymongo.synchronous.cursor.Cursor.next() -> _DocumentType
Advance the cursor.
methodpymongo.synchronous.cursor.Cursor.remove_option(mask:int) -> Cursor[_DocumentType]
Unset arbitrary query flags using a bitmask.
methodpymongo.synchronous.cursor.Cursor.retrieved() -> int
The number of documents retrieved so far.
methodpymongo.synchronous.cursor.Cursor.rewind() -> Cursor[_DocumentType]
Rewind this cursor to its unevaluated state.
methodpymongo.synchronous.cursor.Cursor.skip(skip:int) -> Cursor[_DocumentType]
Skips the first `skip` results of this cursor.
methodpymongo.synchronous.cursor.Cursor.sort(key_or_list:_Hint, direction:Optional[Union[int, str]]=None) -> Cursor[_DocumentType]
Sorts this cursor's results.
methodpymongo.synchronous.cursor.Cursor.where(code:Union[str, Code]) -> Cursor[_DocumentType]
Adds a `$where`_ clause to this query.
methodpymongo.synchronous.database.Database.aggregate(pipeline:_Pipeline, session:Optional[ClientSession]=None, **kwargs:Any) -> CommandCursor[_DocumentType]
Perform a database-level aggregation.
methodpymongo.synchronous.database.Database.name() -> str
The name of this :class:`Database`.
classpymongo.synchronous.encryption.ClientEncryption
Explicit client-side field level encryption.
methodpymongo.synchronous.encryption.ClientEncryption.close() -> None
Release resources.
methodpymongo.synchronous.encryption.ClientEncryption.decrypt(value:Binary) -> Any
Decrypt an encrypted value.
methodpymongo.synchronous.encryption.ClientEncryption.get_key(id:Binary) -> Optional[RawBSONDocument]
Get a data key by id.
methodpymongo.synchronous.encryption.ClientEncryption.get_keys() -> Cursor[RawBSONDocument]
Get all of the data keys.
funcpymongo.synchronous.mongo_client.MongoClient.option_repr(option:str, value:Any) -> str
Fix options whose __repr__ isn't usable in a constructor.
methodpymongo.synchronous.monitor.Monitor.cancel_check() -> None
Cancel any concurrent hello check.
classpymongo.synchronous.pool.Connection
Store a connection with some metadata.
methodpymongo.synchronous.pool.Connection.add_server_api(command:MutableMapping[str, Any]) -> None
Add server_api parameters.
methodpymongo.synchronous.pool.Connection.authenticate(reauthenticate:bool=False) -> None
Authenticate to the server if needed.
methodpymongo.synchronous.pool.Connection.close_conn(reason:Optional[str]) -> None
Close this connection with a reason.
methodpymongo.synchronous.pool.Connection.receive_message(request_id:Optional[int]) -> _OpMsg
Receive a raw BSON message or raise ConnectionFailure.
methodpymongo.synchronous.pool.Connection.send_cluster_time(command:MutableMapping[str, Any], session:Optional[ClientSession], client:Optional[MongoClient[Any]]) -> None
Add $clusterTime.
methodpymongo.synchronous.pool.Connection.send_message(message:bytes, max_doc_size:int) -> None
Send a raw BSON message or raise ConnectionFailure.
methodpymongo.synchronous.pool.Connection.validate_session(client:Optional[MongoClient[Any]], session:Optional[ClientSession]) -> None
Validate this session before use with client.
methodpymongo.synchronous.pool.Pool.checkin(conn:Connection) -> None
Return the connection to the pool, or if it's closed discard it.
methodpymongo.synchronous.pool.Pool.checkout(handler:Optional[_ClientCheckout]=None) -> _PoolCheckout
Get a connection from the pool.
methodpymongo.synchronous.pool.Pool.connect(handler:Optional[_ClientCheckout]=None) -> Connection
Connect to Mongo and return a new Connection.
methodpymongo.synchronous.server.Server.close() -> None
Clear the connection pool and stop the monitor.
methodpymongo.synchronous.server.Server.open() -> None
Start monitoring, or restart after a fork.
methodpymongo.synchronous.server.Server.request_check() -> None
Check the server's state soon.
methodpymongo.synchronous.server.Server.reset(service_id:Optional[ObjectId]=None) -> None
Clear the connection pool.
classpymongo.synchronous.topology.Topology
Monitor a topology of one or more servers.
methodpymongo.synchronous.topology.Topology.close() -> None
Clear pools and terminate monitors.
methodpymongo.synchronous.topology.Topology.data_bearing_servers() -> list[ServerDescription]
Return a list of all data-bearing servers.
methodpymongo.synchronous.topology.Topology.get_arbiters() -> set[_Address]
Return set of arbiter addresses.
methodpymongo.synchronous.topology.Topology.get_primary() -> Optional[_Address]
Return primary's address or None.

About this data

These signatures were extracted from the public source of mongodb/mongo-python-driver using Python's ast module. Argument names, default values, type annotations and return types are taken verbatim from the code. Implementation bodies are never stored. See how it works for details.

Back to all 805 libraries