fFdZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZmZmZmZddlmZmZddlmZddlmZddlmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#dd l$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4er,ddl5Z5ddlZ5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddlm?Z?ddl@mAZAddZBede eCefZDGddejee2ZFy)zDatabase level operations.) annotations)deepcopy) TYPE_CHECKINGAnyGenericMappingMutableMappingNoReturnOptionalSequenceTypeVarUnioncastoverload)DEFAULT_CODEC_OPTIONS CodecOptions)DBRef) Timestamp)_csotcommon)_DatabaseAggregationCommandDatabaseChangeStream Collection) CommandCursor)_ecoc_coll_name_esc_coll_name)CollectionInvalid InvalidNameInvalidOperation)_Op)ReadPreference _ServerMode) _CollationIn _DocumentType_DocumentTypeArg _PipelineN) ClientSession) MongoClient) Connection) ReadConcern)Server) WriteConcerncP|s tddD]}||vstd|zy)z"Check if a database name is valid.z(database name cannot be the empty string) .$/\"z.database names cannot contain the character %rN)r )name invalid_chars Y/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/pymongo/database.py _check_namer:;s6 DEE? 4 NQ]]^ ^@_CodecDocumentType)boundc heZdZdZ d' d(fd Zed)dZed*dZ d' d+dZd,dZ d,dZ d-d Z d*d Z d.d Z d.d Z d' d/d Z d0dZej$ d1 d2dZ d3 d4dZ d5 d6dZedddej0edddf d7dZedddej0ddddf d8dZdddej0edddf d9dZe d: d;dZe d< d=dZej$ d: d>dZej$ d? d@dZ d3 dAdZ dBdZ dC dDdZ dC dEd Z dF dGd!Z!ej$ dC dHd"Z" dI dJd#Z#dZ$dKd$Z%e%Z&dKd%Z' dF dLd&Z(xZ)S)MDatabasezA Mongo database.NcBt||xs |j|xs |j|xs |j|xs |j t |ts td|dk7r t|||_ ||_ |jj|_y)aGet a database by client and name. Raises :class:`TypeError` if `name` is not an instance of :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if `name` is not a valid database name. :param client: A :class:`~pymongo.mongo_client.MongoClient` instance. :param name: The database name. :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. If ``None`` (the default) client.codec_options is used. :param read_preference: The read preference to use. If ``None`` (the default) client.read_preference is used. :param write_concern: An instance of :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the default) client.write_concern is used. :param read_concern: An instance of :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the default) client.read_concern is used. .. seealso:: The MongoDB documentation on `databases `_. .. versionchanged:: 4.0 Removed the eval, system_js, error, last_status, previous_error, reset_error_history, authenticate, logout, collection_names, current_op, add_user, remove_user, profiling_level, set_profiling_level, and profiling_info methods. See the :ref:`pymongo4-migration-guide`. .. versionchanged:: 3.2 Added the read_concern option. .. versionchanged:: 3.0 Added the codec_options, read_preference, and write_concern options. :class:`~pymongo.database.Database` no longer returns an instance of :class:`~pymongo.collection.Collection` for attribute names with leading underscores. You must use dict-style lookups instead:: db['__my_collection__'] Not: db.__my_collection__ zname must be an instance of strz $externalN)super__init__ codec_optionsread_preference write_concern read_concern isinstancestr TypeErrorr:_Database__name_Database__clientoptionstimeout_timeout)selfclientr7rCrDrErF __class__s r9rBzDatabase.__init__Ksj   1V11  5v55  1V11  /F//  $$=> > ;    4: .. r;c|jS)z/The client instance for this :class:`Database`.)rKrOs r9rPzDatabase.clients}}r;c|jS)z#The name of this :class:`Database`.)rJrSs r9r7z Database.names{{r;c t|j|j|xs |j|xs |j|xs |j |xs |j S)aMGet a clone of this database changing the specified settings. >>> db1.read_preference Primary() >>> from pymongo.read_preferences import Secondary >>> db2 = db1.with_options(read_preference=Secondary([{'node': 'analytics'}])) >>> db1.read_preference Primary() >>> db2.read_preference Secondary(tag_sets=[{'node': 'analytics'}], max_staleness=-1, hedge=None) :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. If ``None`` (the default) the :attr:`codec_options` of this :class:`Collection` is used. :param read_preference: The read preference to use. If ``None`` (the default) the :attr:`read_preference` of this :class:`Collection` is used. See :mod:`~pymongo.read_preferences` for options. :param write_concern: An instance of :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the default) the :attr:`write_concern` of this :class:`Collection` is used. :param read_concern: An instance of :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the default) the :attr:`read_concern` of this :class:`Collection` is used. .. versionadded:: 3.8 )r?rPrJrCrDrErF)rOrCrDrErFs r9 with_optionszDatabase.with_optionssXJ KK KK  /T//  3t33  /T//  -D--   r;ct|tr4|j|jk(xr|j|j k(St SN)rGr?rKrPrJr7NotImplementedrOothers r9__eq__zDatabase.__eq__s7 eX &==ELL0NT[[EJJ5N Nr;c||k( SrXrZs r9__ne__zDatabase.__ne__s5=  r;cDt|j|jfSrX)hashrKrJrSs r9__hash__zDatabase.__hash__sT]]DKK011r;c<d|jd|jdS)Nz Database(z, ))rKrJrSs r9__repr__zDatabase.__repr__s 4==+2dkk_A>>r;c p|jdrtd|d|d|d|j|S)Get a collection of this database by name. Raises InvalidName if an invalid collection name is used. :param name: the name of the collection to get _zDatabase has no attribute z. To access the z collection, use database[z].) startswithAttributeError __getitem__rOr7s r9 __getattr__zDatabase.__getattr__sL ??3  ,TH4DTF,THB8 %%r;ct||S)rgrrls r9rkzDatabase.__getitem__s$%%r;c $t||d||||S)a+Get a :class:`~pymongo.collection.Collection` with the given name and options. Useful for creating a :class:`~pymongo.collection.Collection` with different codec options, read preference, and/or write concern from this :class:`Database`. >>> db.read_preference Primary() >>> coll1 = db.test >>> coll1.read_preference Primary() >>> from pymongo import ReadPreference >>> coll2 = db.get_collection( ... 'test', read_preference=ReadPreference.SECONDARY) >>> coll2.read_preference Secondary(tag_sets=None) :param name: The name of the collection - a string. :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. If ``None`` (the default) the :attr:`codec_options` of this :class:`Database` is used. :param read_preference: The read preference to use. If ``None`` (the default) the :attr:`read_preference` of this :class:`Database` is used. See :mod:`~pymongo.read_preferences` for options. :param write_concern: An instance of :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the default) the :attr:`write_concern` of this :class:`Database` is used. :param read_concern: An instance of :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the default) the :attr:`read_concern` of this :class:`Database` is used. Fr)rOr7rCrDrErFs r9get_collectionzDatabase.get_collections'X         r;c 8|jd}|r&ttttft |S|j jjr|j jjjr|j jjjj|jd|r`ttttft |j jjj|jd|S|rm|j jjrM||j}|jdr)ttttft |dSy)NencryptedFieldsr1) getrrrHrrrPrLauto_encryption_opts_encrypted_fields_mapr7)rOkwargs coll_nameask_dbencrypted_fieldsrLs r9_get_encrypted_fieldszDatabase._get_encrypted_fields$sB"::&78 S)84D+EF F KK   4 4 ##88NN ##88NNRR99+Qyk*S!KK''<<RR99+Qyk2  dkk))>>9o--/G{{,-GCH-x@Q8R/STTr;Tc |j||d} | rtjd| | |d<|jd} | rtjd| |jj |5} |r3| r | j s%||jd|i| vrtd|zt||d||||fd| i|cd d d S#1swYy xYw) aCreate a new :class:`~pymongo.collection.Collection` in this database. Normally collection creation is automatic. This method should only be used to specify options on creation. :class:`~pymongo.errors.CollectionInvalid` will be raised if the collection already exists. :param name: the name of the collection to create :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. If ``None`` (the default) the :attr:`codec_options` of this :class:`Database` is used. :param read_preference: The read preference to use. If ``None`` (the default) the :attr:`read_preference` of this :class:`Database` is used. :param write_concern: An instance of :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the default) the :attr:`write_concern` of this :class:`Database` is used. :param read_concern: An instance of :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the default) the :attr:`read_concern` of this :class:`Database` is used. :param collation: An instance of :class:`~pymongo.collation.Collation`. :param session: a :class:`~pymongo.client_session.ClientSession`. :param `check_exists`: if True (the default), send a listCollections command to check if the collection already exists before creation. :param kwargs: additional keyword arguments will be passed as options for the `create collection command`_ All optional `create collection command`_ parameters should be passed as keyword arguments to this method. Valid options include, but are not limited to: - ``size`` (int): desired initial size for the collection (in bytes). For capped collections this size is the max size of the collection. - ``capped`` (bool): if True, this is a capped collection - ``max`` (int): maximum number of objects if capped (optional) - ``timeseries`` (dict): a document specifying configuration options for timeseries collections - ``expireAfterSeconds`` (int): the number of seconds after which a document in a timeseries collection expires - ``validator`` (dict): a document specifying validation rules or expressions for the collection - ``validationLevel`` (str): how strictly to apply the validation rules to existing documents during an update. The default level is "strict" - ``validationAction`` (str): whether to "error" on invalid documents (the default) or just "warn" about the violations but allow invalid documents to be inserted - ``indexOptionDefaults`` (dict): a document specifying a default configuration for indexes when creating a collection - ``viewOn`` (str): the name of the source collection or view from which to create the view - ``pipeline`` (list): a list of aggregation pipeline stages - ``comment`` (str): a user-provided comment to attach to this command. This option is only supported on MongoDB >= 4.4. - ``encryptedFields`` (dict): **(BETA)** Document that describes the encrypted fields for Queryable Encryption. For example:: { "escCollection": "enxcol_.encryptedCollection.esc", "ecocCollection": "enxcol_.encryptedCollection.ecoc", "fields": [ { "path": "firstName", "keyId": Binary.from_uuid(UUID('00000000-0000-0000-0000-000000000000')), "bsonType": "string", "queries": {"queryType": "equality"} }, { "path": "ssn", "keyId": Binary.from_uuid(UUID('04104104-1041-0410-4104-104104104104')), "bsonType": "string" } ] } - ``clusteredIndex`` (dict): Document that specifies the clustered index configuration. It must have the following form:: { // key pattern must be {_id: 1} key: , // required unique: , // required, must be `true` name: , // optional, otherwise automatically generated v: , // optional, must be `2` if provided } - ``changeStreamPreAndPostImages`` (dict): a document with a boolean field ``enabled`` for enabling pre- and post-images. .. versionchanged:: 4.2 Added the ``check_exists``, ``clusteredIndex``, and ``encryptedFields`` parameters. .. versionchanged:: 3.11 This method is now supported inside multi-document transactions with MongoDB 4.4+. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.4 Added the collation option. .. versionchanged:: 3.0 Added the codec_options, read_preference, and write_concern options. .. _create collection command: https://mongodb.com/docs/manual/reference/command/create FrrclusteredIndexr7)filtersessionzcollection %s already existsTr~N) rzrvalidate_is_mappingrsrK _tmp_sessionin_transactionlist_collection_namesrr) rOr7rCrDrErFr~ check_existsrvryclustered_indexss r9create_collectionzDatabase.create_collection?sz 55fdEJ   & &'8:J K(8F$ % **%56   & &'7 I ]] ' ' 0 A!"2"2D66vtnVW6XX'(F(MNN      s 5A CCc B|jj|d5}t|t|||dudddii}|jj |j |j |||j tjcdddS#1swYyxYw) an Perform a database-level aggregation. See the `aggregation pipeline`_ documentation for a list of stages that are supported. .. code-block:: python # Lists all operations currently running on the server. with client.admin.aggregate([{"$currentOp": {}}]) as cursor: for operation in cursor: print(operation) The :meth:`aggregate` method obeys the :attr:`read_preference` of this :class:`Database`, except when ``$out`` or ``$merge`` are used, in which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY` is used. .. note:: This method does not support the 'explain' option. Please use :meth:`~pymongo.database.Database.command` instead. .. note:: The :attr:`~pymongo.database.Database.write_concern` of this collection is automatically applied to this operation. :param pipeline: a list of aggregation pipeline stages :param session: a :class:`~pymongo.client_session.ClientSession`. :param kwargs: extra `aggregate command`_ parameters. All optional `aggregate command`_ parameters should be passed as keyword arguments to this method. Valid options include, but are not limited to: - `allowDiskUse` (bool): Enables writing to temporary files. When set to True, aggregation stages can write data to the _tmp subdirectory of the --dbpath directory. The default is False. - `maxTimeMS` (int): The maximum amount of time to allow the operation to run in milliseconds. - `batchSize` (int): The maximum number of documents to return per batch. Ignored if the connected mongod or mongos does not support returning aggregate results using a cursor. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `let` (dict): A dict of parameter names and values. Values must be constant or closed expressions that do not reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. ``"$$var"``). This option is only supported on MongoDB >= 5.0. :return: A :class:`~pymongo.command_cursor.CommandCursor` over the result set. .. versionadded:: 3.9 .. _aggregation pipeline: https://mongodb.com/docs/manual/reference/operator/aggregation-pipeline .. _aggregate command: https://mongodb.com/docs/manual/reference/command/aggregate FcloseNcursor firstBatch) user_fields) retryable operation) rPrrr_retryable_read get_cursorget_read_preference_performs_writer" AGGREGATE)rOpipeliner~rvrcmds r9 aggregatezDatabase.aggregates|[[ % %gU % ; q-t#% a'89 C;;..''*!111-- /   s A-BBc 2t|||||||||| | | |  S)aWatch changes on this database. Performs an aggregation with an implicit initial ``$changeStream`` stage and returns a :class:`~pymongo.change_stream.DatabaseChangeStream` cursor which iterates over changes on all collections in this database. Introduced in MongoDB 4.0. .. code-block:: python with db.watch() as stream: for change in stream: print(change) The :class:`~pymongo.change_stream.DatabaseChangeStream` iterable blocks until the next change document is returned or an error is raised. If the :meth:`~pymongo.change_stream.DatabaseChangeStream.next` method encounters a network error when retrieving a batch from the server, it will automatically attempt to recreate the cursor such that no change events are missed. Any error encountered during the resume attempt indicates there may be an outage and will be raised. .. code-block:: python try: with db.watch([{"$match": {"operationType": "insert"}}]) as stream: for insert_change in stream: print(insert_change) except pymongo.errors.PyMongoError: # The ChangeStream encountered an unrecoverable error or the # resume attempt failed to recreate the cursor. logging.error("...") For a precise description of the resume process see the `change streams specification`_. :param pipeline: A list of aggregation pipeline stages to append to an initial ``$changeStream`` stage. Not all pipeline stages are valid after a ``$changeStream`` stage, see the MongoDB documentation on change streams for the supported stages. :param full_document: The fullDocument to pass as an option to the ``$changeStream`` stage. Allowed values: 'updateLookup', 'whenAvailable', 'required'. When set to 'updateLookup', the change notification for partial updates will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred. :param full_document_before_change: Allowed values: 'whenAvailable' and 'required'. Change events may now result in a 'fullDocumentBeforeChange' response field. :param resume_after: A resume token. If provided, the change stream will start returning changes that occur directly after the operation specified in the resume token. A resume token is the _id value of a change document. :param max_await_time_ms: The maximum time in milliseconds for the server to wait for changes before responding to a getMore operation. :param batch_size: The maximum number of documents to return per batch. :param collation: The :class:`~pymongo.collation.Collation` to use for the aggregation. :param start_at_operation_time: If provided, the resulting change stream will only return changes that occurred at or after the specified :class:`~bson.timestamp.Timestamp`. Requires MongoDB >= 4.0. :param session: a :class:`~pymongo.client_session.ClientSession`. :param start_after: The same as `resume_after` except that `start_after` can resume notifications after an invalidate event. This option and `resume_after` are mutually exclusive. :param comment: A user-provided comment to attach to this command. :param show_expanded_events: Include expanded events such as DDL events like `dropIndexes`. :return: A :class:`~pymongo.change_stream.DatabaseChangeStream` cursor. .. versionchanged:: 4.3 Added `show_expanded_events` parameter. .. versionchanged:: 4.2 Added ``full_document_before_change`` parameter. .. versionchanged:: 4.1 Added ``comment`` parameter. .. versionchanged:: 3.9 Added the ``start_after`` parameter. .. versionadded:: 3.7 .. seealso:: The MongoDB documentation on `changeStreams `_. .. _change streams specification: https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.md )show_expanded_eventsr) rOr full_document resume_aftermax_await_time_ms batch_size collationstart_at_operation_timer~ start_aftercommentfull_document_before_changers r9watchzDatabase.watch)s9`$        #    '!5  r;rFc yrXr^ rOconncommandvaluecheckallowable_errorsrDrCrEparse_write_concern_errorr~rvs r9_commandzDatabase._command r;.c yrXr^rs r9rzDatabase._commandrr;c  t|tr||i}|j| |jj | 5} |j |j ||||||| | |j cdddS#1swYyxYw)zInternal command helper.)rErr~rPN)rGrHupdaterKrrrJ) rOrrrrrrDrCrErr~rvrs r9rzDatabase._commands" gs #&Gv ]] ' ' 0 A<<  +*C}}    s /A::Bc yrXr^ rOrrrrrDrCr~rrvs r9rzDatabase.command r;c yrXr^rs r9rzDatabase.commandrr;c f|xst} ||| d<t|tr|} ntt |} |&|xr|j xst j}|jj||| 5\} }|j| |||||| fd|i| cdddS#1swYyxYw)aIssue a MongoDB command. Send command `command` to the database and return the response. If `command` is an instance of :class:`str` then the command {`command`: `value`} will be sent. Otherwise, `command` must be an instance of :class:`dict` and will be sent as is. Any additional keyword arguments will be added to the final command document before it is sent. For example, a command like ``{buildinfo: 1}`` can be sent using: >>> db.command("buildinfo") OR >>> db.command({"buildinfo": 1}) For a command where the value matters, like ``{count: collection_name}`` we can do: >>> db.command("count", collection_name) OR >>> db.command({"count": collection_name}) For commands that take additional arguments we can use kwargs. So ``{count: collection_name, query: query}`` becomes: >>> db.command("count", collection_name, query=query) OR >>> db.command({"count": collection_name, "query": query}) :param command: document representing the command to be issued, or the name of the command (for simple commands only). .. note:: the order of keys in the `command` document is significant (the "verb" must come first), so commands which require multiple keys (e.g. `findandmodify`) should be done with this in mind. :param value: value to use for the command verb when `command` is passed as a string :param check: check the response for errors, raising :class:`~pymongo.errors.OperationFailure` if there are any :param allowable_errors: if `check` is ``True``, error messages in this list will be ignored by error-checking :param read_preference: The read preference for this operation. See :mod:`~pymongo.read_preferences` for options. If the provided `session` is in a transaction, defaults to the read preference configured for the transaction. Otherwise, defaults to :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`. :param codec_options: A :class:`~bson.codec_options.CodecOptions` instance. :param session: A :class:`~pymongo.client_session.ClientSession`. :param comment: A user-provided comment to attach to this command. :param kwargs: additional keyword arguments will be added to the command document before it is sent .. note:: :meth:`command` does **not** obey this Database's :attr:`read_preference` or :attr:`codec_options`. You must use the ``read_preference`` and ``codec_options`` parameters instead. .. note:: :meth:`command` does **not** apply any custom TypeDecoders when decoding the command response. .. note:: If this client has been configured to use MongoDB Stable API (see :ref:`versioned-api-ref`), then :meth:`command` will automatically add API versioning options to the given command. Explicitly adding API versioning options in the command and declaring an API version on the client is not supported. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.0 Removed the `as_class`, `fields`, `uuid_subtype`, `tag_sets`, and `secondary_acceptable_latency_ms` option. Removed `compile_re` option: PyMongo now always represents BSON regular expressions as :class:`~bson.regex.Regex` objects. Use :meth:`~bson.regex.Regex.try_compile` to attempt to convert from a BSON regular expression to a Python regular expression object. Added the ``codec_options`` parameter. .. seealso:: The MongoDB documentation on `commands `_. Nrrr~) rrGrHnextiter_txn_read_preferencer#PRIMARYrK_conn_for_readsr) rOrrrrrDrCr~rrvopts command_name connections r9rzDatabase.command sL5 5   'F9  gs #"LW .L  "&I7+G+G+IdnNdNdO ]] * *?G| * \ a   4==         s ?B''B0c t|tr|} ntt|} |jj |d5} |xst } |&| xr| jxstj}|jj|| | 5\} }|j| ||dd|| fd| i|} |jd|}| jdrFt|| d| j|| |du| }|j!| |cdddcdddSt#d #1swYnxYw dddy#1swYyxYw) a Issue a MongoDB command and parse the response as a cursor. If the response from the server does not include a cursor field, an error will be thrown. Otherwise, behaves identically to issuing a normal MongoDB command. :param command: document representing the command to be issued, or the name of the command (for simple commands only). .. note:: the order of keys in the `command` document is significant (the "verb" must come first), so commands which require multiple keys (e.g. `findandmodify`) should use an instance of :class:`~bson.son.SON` or a string and kwargs instead of a Python `dict`. :param value: value to use for the command verb when `command` is passed as a string :param read_preference: The read preference for this operation. See :mod:`~pymongo.read_preferences` for options. If the provided `session` is in a transaction, defaults to the read preference configured for the transaction. Otherwise, defaults to :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`. :param codec_options`: A :class:`~bson.codec_options.CodecOptions` instance. :param session: A :class:`~pymongo.client_session.ClientSession`. :param comment: A user-provided comment to attach to future getMores for this command. :param max_await_time_ms: The number of ms to wait for more data on future getMores for this command. :param kwargs: additional keyword arguments will be added to the command document before it is sent .. note:: :meth:`command` does **not** obey this Database's :attr:`read_preference` or :attr:`codec_options`. You must use the ``read_preference`` and ``codec_options`` parameters instead. .. note:: :meth:`command` does **not** apply any custom TypeDecoders when decoding the command response. .. note:: If this client has been configured to use MongoDB Stable API (see :ref:`versioned-api-ref`), then :meth:`command` will automatically add API versioning options to the given command. Explicitly adding API versioning options in the command and declaring an API version on the client is not supported. .. seealso:: The MongoDB documentation on `commands `_. FrNTr~$cmdrDr)rr~explicit_sessionrz!Command does not return a cursor.)rGrHrrrKrrrr#rrrrprsraddress_maybe_pin_connectionr!)rOrrrDrCr~rrrvr tmp_sessionrrresponsecoll cmd_cursors r9cursor_commandzDatabase.cursor_commandsx gs #"LW .L ]] ' 'u ' =$ P 9$9D&FK$D$D$F#,#++ .. \Z P_(4==# (  **6?*S<<)!. * *; +)0)< '"J44T:%7 P P$ P$ PH++NOO; P P P$ P$ P$ Ps,AD?A6D) D? D))D2 .D??Ec|xr|jxstj} dfd }jj ||||S)z5Same as command but used for retryable read commands.c.j|||S)NrDr~)r)r~_serverrrDrrOs r9_cmdz.Database._retryable_read_command.._cmds' == / ! r;) r~Optional[ClientSession]rr-rr+rDr$returndict[str, Any])rr#rrKr)rOrrr~rDrs`` r9_retryable_read_commandz Database._retryable_read_commandss#Ew'C'C'E`.J`J` ,   )   }},,T?GYWWr;c tttttf|j d|}did}|j ||jj|d5}|j||||d}t|||j||d u|jd  } d d d  j|| S#1swYxYw) z Internal listCollections helper.rrr)listCollectionsrFrrrNr)r~rr)rrr rHrrprrKrrrrrsr) rOrr~rDrvrrrrrs r9_list_collectionszDatabase._list_collections s ~c3h/ 0     H #$r2 6 ]] ' 'u ' = ]]4oWb]cF' #!(!4 * J  ((.  s )AC  Cc ||d<|xr|jxstj}||d< dfd }jj |||t j S)aGet a cursor over the collections of this database. :param session: a :class:`~pymongo.client_session.ClientSession`. :param filter: A query document to filter the list of collections returned from the listCollections command. :param comment: A user-provided comment to attach to this command. :param kwargs: Optional parameters of the `listCollections command `_ can be passed as keyword arguments to this method. The supported options differ by server version. :return: An instance of :class:`~pymongo.command_cursor.CommandCursor`. .. versionadded:: 3.6 r}rc0j||fd|iS)NrD)r)r~rrrDrvrOs r9rz'Database.list_collections.._cmdIs% *4))$cc\bc cr;r) r~rrr-rr+rDr$r'CommandCursor[MutableMapping[str, Any]])rr#rrKrr"LIST_COLLECTIONS)rOr~r}rrv read_prefrs` ` r9list_collectionszDatabase.list_collections)s4  %F8 ?!=!=!?ZNDZDZ   'F9  d, d d d)  d 5  d}},, )W0D0D-  r;c |||d<|d|d<n4tjd|||d<|rt|dk(r d|vrd|d<|jdd|i|Dcgc]}|d c}Scc}w) aGet a list of all the collection names in this database. For example, to list all non-system collections:: filter = {"name": {"$regex": r"^(?!system\.)"}} db.list_collection_names(filter=filter) :param session: a :class:`~pymongo.client_session.ClientSession`. :param filter: A query document to filter the list of collections returned from the listCollections command. :param comment: A user-provided comment to attach to this command. :param kwargs: Optional parameters of the `listCollections command `_ can be passed as keyword arguments to this method. The supported options differ by server version. .. versionchanged:: 3.8 Added the ``filter`` and ``**kwargs`` parameters. .. versionadded:: 3.6 rTnameOnlyr}rr7r~r^)rrlenr)rOr~r}rrvresults r9rzDatabase.list_collection_namesUs@   'F9  >!%F:   & &x 8%F8 c&kQ.6V3C%)z"-BT-B-B-]7-]V\-]^6v^^^s A)c d|i}|||d<|jj|tj5}|j ||ddg|j |d|cdddS#1swYyxYw)Ndroprrz ns not foundT)rrErr~)rK_conn_for_writesr"DROPr_write_concern_for)rOr7r~rrrs r9 _drop_helperzDatabase._drop_helpers4.  !(GI  ]] + +Gsxx + H J=="0"!5"55g>*. !   s (A))A2cl|}t|tr |j}t|ts t d|j d|i|d}|rRt jd||jt|||||jt|||||j|||S)aDrop a collection. :param name_or_collection: the name of a collection to drop or the collection object itself :param session: a :class:`~pymongo.client_session.ClientSession`. :param comment: A user-provided comment to attach to this command. :param encrypted_fields: **(BETA)** Document that describes the encrypted fields for Queryable Encryption. For example:: { "escCollection": "enxcol_.encryptedCollection.esc", "ecocCollection": "enxcol_.encryptedCollection.ecoc", "fields": [ { "path": "firstName", "keyId": Binary.from_uuid(UUID('00000000-0000-0000-0000-000000000000')), "bsonType": "string", "queries": {"queryType": "equality"} }, { "path": "ssn", "keyId": Binary.from_uuid(UUID('04104104-1041-0410-4104-104104104104')), "bsonType": "string" } ] } .. note:: The :attr:`~pymongo.database.Database.write_concern` of this database is automatically applied to this operation. .. versionchanged:: 4.2 Added ``encrypted_fields`` parameter. .. versionchanged:: 4.1 Added ``comment`` parameter. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.4 Apply this database's write concern automatically to this operation when connected to MongoDB >= 3.4. z-name_or_collection must be an instance of strrrTryr~r) rGrr7rHrIrzrrrrr)rOname_or_collectionr~rryr7s r9drop_collectionzDatabase.drop_collectionsp" dJ '99D$$KL L55  0 1      & &'9;K L   /6QX      0$7RY    w88r;c|}t|tr |j}t|ts t d|||d}|||d<|||d<|j ||} d} d| vr=| d} | j dd k7s| j d d k7rt|d | d | vrt| d jD]]\} } d| vr>| d} | j dd k7s| j d d k7s8t|d | | jd dr[d} nn| jd dsd} | st|d | | S)aValidate a collection. Returns a dict of validation info. Raises CollectionInvalid if validation fails. See also the MongoDB documentation on the `validate command`_. :param name_or_collection: A Collection object or the name of a collection to validate. :param scandata: Do extra checks beyond checking the overall structure of the collection. :param full: Have the server do a more thorough scan of the collection. Use with `scandata` for a thorough scan of the structure of the collection and the individual documents. :param session: a :class:`~pymongo.client_session.ClientSession`. :param background: A boolean flag that determines whether the command runs in the background. Requires MongoDB 4.4+. :param comment: A user-provided comment to attach to this command. .. versionchanged:: 4.1 Added ``comment`` parameter. .. versionchanged:: 3.11 Added ``background`` parameter. .. versionchanged:: 3.6 Added ``session`` parameter. .. _validate command: https://mongodb.com/docs/manual/reference/command/validate/ z;name_or_collection must be an instance of str or Collection)validatescandatafullr background)r~Tr exceptioncorruptz invalid: rawvalidF) rGrr7rHrIrfindritemsrs)rOrrrr~rrr7rrrinforhress r9validate_collectionzDatabase.validate_collectionspT" dJ '99D$$YZ ZXtD  $C N  ! *C c73 v (#Dyy%+tyy/Cr/I'4& 4&(ABB f_ ---/3s?x=Dyy-3tyy7Kr7Q/4& 4&0IJJ%0!E0GU+E#tfJvj$AB B r;ctd)Nz!'Database' object is not iterable)rIrSs r9__next__zDatabase.__next__8s;<%'5U CD D >> %%..DKK*G%%*^^$6eDKK?!M /tE$$%.. EHH  '. CI  r;)NNNN)rPMongoClient[_DocumentType]r7rHrC(Optional[CodecOptions[_DocumentTypeArg]]rDOptional[_ServerMode]rEOptional[WriteConcern]rFOptional[ReadConcern]rNone)rr )rrH) rCr rDr rEr rFr rzDatabase[_DocumentType])r[rrbool)rint)r7rHrCollection[_DocumentType]) r7rHrCr rDr rEr rFr rr)rvzMapping[str, Any]rwrHrxrrOptional[Mapping[str, Any]])NNNNNT)r7rHrCr rDr rEr rFr r~rrOptional[bool]rvrrrrX)rr(r~rrvrrCommandCursor[_DocumentType]) NNNNNNNNNNNN)rzOptional[_Pipeline]r Optional[str]rrr Optional[int]rrrzOptional[_CollationIn]rzOptional[Timestamp]r~rrrr Optional[Any]rrrrrz#DatabaseChangeStream[_DocumentType])rr+r$Union[str, MutableMapping[str, Any]]rrrrr#Optional[Sequence[Union[str, int]]]rDr$rCzCodecOptions[dict[str, Any]]rEr rrr~rrvrrr)rr+rrrrrrrrrDr$rC CodecOptions[_CodecDocumentType]rEr rrr~rrvrrr<)rr+rrrrrrrrrDr$rCzEUnion[CodecOptions[dict[str, Any]], CodecOptions[_CodecDocumentType]]rEr rrr~rrvrr)Union[dict[str, Any], _CodecDocumentType])rTNNNNN)rrrrrrrrrDr rCrr~rrrrvrrr)rTNN.NN)rrrrrrrrrDr rCrr~rrrrvrrr<)rrrrrrrrrDr rC=Optional[bson.codec_options.CodecOptions[_CodecDocumentType]]r~rrrrvrrr)rNNNNN)rrrrrDr rCrr~rrrrrrvrrr)rrrrHr~rrr) rr+r~rrDr$rvrrr)NNN) r~rr}rrrrvrrr) r~rr}rrrrvrrz list[str])NN)r7rHr~rrrrr) r(Union[str, Collection[_DocumentTypeArg]]r~rrrryrrr)FFNNN)rrrrrrr~rrrrrrr)rr ) rrr~rrrrvrrzOptional[_DocumentType])*__name__ __module__ __qualname____doc__rBpropertyrPr7rVr\r_rbrermrkrprzrapplyrrrrr#rrrrrrrrrrrr__iter__rrrr __classcell__)rQs@r9r?r?Hsb  CG1504.2D/*D/D/@ D/ / D/ . D/,D/ D/L CG1504.2 , ?, /, . , , , ! , \ !2? &&CG1504.2 4 4 @4 / 4 . 4 , 4  #4 l'47AE $6 [[CG1504.2+/'+XX@X/ X . X , X)X%XX #XXvGKM!M,CMVYM %Mb)-'+48+/$(,07;+/37!%59/3~ %~ %~ 2 ~ ) ~ " ~ *~ "5~ )~ 1~ ~ &3~ -~  -~ @ @D'5'='=6K04*/+/  6     >  % 4 . $( )      @D'5'='=:=04*/+/  6     >  % 8 . $( )     (@D'5'='= "04*/+/!!6! !  ! > !%! !.!$(!)!! 3!F@D15"+/!%  5      >  /    )           @D15:=+/!%  5      >  /  8  )            [[@D15W[+/!%~5~~ ~ > ~ / ~U~)~~~ 3~~@ [[15W[+/!%+/dP5dPdP/ dP U dP ) dPdP)dPdP &dPdPT,0 X5XX) X  X0)%    1 >,0.2!% * (* ,*  *  * 1 * \,0.2!% -_(-_,-_ -_  -_  -_`\`"9KX " [[,0!%8< K9DK9)K9 K9 6 K9  K9K9`+/%)!%PDPP P ) P # PP PfH= D ,0!% ( ( )(  (  ( ! ( r;r?)r7rHrr)Gr! __future__rcopyrtypingrrrrr r r r r rrrbson.codec_optionsrr bson.dbrefrbson.timestamprpymongorrpymongo.aggregationrpymongo.change_streamrpymongo.collectionrpymongo.command_cursorrpymongo.commonrrpymongo.errorsrr r!pymongo.operationsr"pymongo.read_preferencesr#r$pymongo.typingsr%r&r'r(bsonpymongo.client_sessionr)pymongo.mongo_clientr* pymongo.poolr+pymongo.read_concernr,pymongo.serverr-pymongo.write_concernr.r:rHr< BaseObjectr?r^r;r9r>s!"    C$!;6)0:KK"@TT40'0%2_1c9JKd v  '-"8d r;