o SbG @s2dZddlmZmZmZmZmZmZmZm Z ddl m Z ddl m Z ddlmZmZmZddlmZmZmZddlmZmZmZGdd d eZeeee eeeeefffZe eefZGd d d eZ Gd d d eZ!GdddeZ"GdddeZ#Gddde#Z$Gddde#Z%GdddeZ&dS)zOperation class definitions.)AnyDictListMappingOptionalSequenceTupleUnion)helpers)validate_collation_or_none)validate_booleanvalidate_is_mapping validate_list)_gen_index_name_index_document _index_list) _CollationIn _DocumentIn _Pipelinec@sZeZdZdZdZdeddfddZdd Zd d Zd e de fd dZ d e de fddZ dS) InsertOnez#Represents an insert_one operation._docdocumentreturnNcCs ||_dS)zCreate an InsertOne instance. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `document`: The document to insert. If the document is missing an _id field one will be added. Nr)selfrr9/tmp/pip-target-onvjaxws/lib/python/pymongo/operations.py__init__s zInsertOne.__init__cCs||jdS)3Add this operation to the _Bulk instance `bulkobj`.N)Z add_insertrrZbulkobjrrr _add_to_bulk)szInsertOne._add_to_bulkcCs d|jfS)Nz InsertOne(%r)rrrrr__repr__-s zInsertOne.__repr__othercCs t|t|kr|j|jkStSN)typerNotImplementedrr#rrr__eq__0s zInsertOne.__eq__cC ||k Sr$rr'rrr__ne__5 zInsertOne.__ne__) __name__ __module__ __qualname____doc__ __slots__rrr r"rboolr(r*rrrrrs rc @xeZdZdZdZ  ddeeefdee dee ddfdd Z d d Z d d Z dedefddZdedefddZdS) DeleteOnez"Represents a delete_one operation._filter _collation_hintNfilter collationhintrcCD|dur td||durt|tst|}||_||_||_dS)aCreate a DeleteOne instance. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `filter`: A query that matches the document to delete. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `hint` (optional): An index to use to support the query predicate specified either by its string name, or in the same format as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``). This option is only supported on MongoDB 4.4 and above. .. versionchanged:: 3.11 Added the ``hint`` option. .. versionchanged:: 3.5 Added the `collation` option. Nr8r isinstancestrr rr5r6r7rr8r9r:rrrrB    zDeleteOne.__init__cC|j|jd|j|jddS)rr9r:NZ add_deleter5r6r7rrrrr ezDeleteOne._add_to_bulkcCd|j|jfS)NzDeleteOne(%r, %r)r5r6r!rrrr"izDeleteOne.__repr__r#cC,t|t|kr|j|jf|j|jfkStSr$r%r5r6r&r'rrrr(lzDeleteOne.__eq__cCr)r$rr'rrrr*qr+zDeleteOne.__ne__NNr,r-r.r/r0rr>rrr _IndexKeyHintrr r"r1r(r*rrrrr3=$  #r3c @r2) DeleteManyz#Represents a delete_many operation.r4Nr8r9r:rcCr;)a!Create a DeleteMany instance. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `filter`: A query that matches the documents to delete. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `hint` (optional): An index to use to support the query predicate specified either by its string name, or in the same format as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``). This option is only supported on MongoDB 4.4 and above. .. versionchanged:: 3.11 Added the ``hint`` option. .. versionchanged:: 3.5 Added the `collation` option. Nr8r<r?rrrrzr@zDeleteMany.__init__cCrA)rrrCNrDrrrrr rEzDeleteMany._add_to_bulkcCrF)NzDeleteMany(%r, %r)rGr!rrrr"rHzDeleteMany.__repr__r#cCrIr$rJr'rrrr(rKzDeleteMany.__eq__cCr)r$rr'rrrr*r+zDeleteMany.__ne__rLrMrrrrrPurOrPc @seZdZdZdZ   ddeeefdeeefdede e d e e d df d d Z d dZ ded efddZded efddZddZdS) ReplaceOnez#Represents a replace_one operation.)r5r_upsertr6r7FNr8 replacementupsertr9r:rcCsb|dur td||durtd||dur t|ts t|}||_||_||_||_ ||_ dS)aCreate a ReplaceOne instance. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `filter`: A query that matches the document to replace. - `replacement`: The new document. - `upsert` (optional): If ``True``, perform an insert if no documents match the filter. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `hint` (optional): An index to use to support the query predicate specified either by its string name, or in the same format as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``). This option is only supported on MongoDB 4.2 and above. .. versionchanged:: 3.11 Added the ``hint`` option. .. versionchanged:: 3.5 Added the ``collation`` option. Nr8rT) r r r=r>r rr5rrRr6r7)rr8rSrTr9r:rrrrs     zReplaceOne.__init__cCs"|j|j|j|j|j|jddS)rrCN)Z add_replacer5rrRr6r7rrrrr s zReplaceOne._add_to_bulkr#cCsDt|t|kr |j|j|j|j|jf|j|j|j|j|jfkStSr$)r%r5rrRr6r7r&r'rrrr(szReplaceOne.__eq__cCr)r$rr'rrrr*r+zReplaceOne.__ne__cCs"d|jj|j|j|j|j|jfS)Nz%s(%r, %r, %r, %r, %r)) __class__r,r5rrRr6r7r!rrrr"szReplaceOne.__repr__)FNN)r,r-r.r/r0rr>rr1rrrNrr r(r*r"rrrrrQs.   - rQc@s4eZdZdZdZddZddZddZd d Zd S) _UpdateOpz)Private base class for update operations.)r5rrRr6_array_filtersr7cCsz|dur td||durtd||durtd||dur)t|ts)t|}||_||_||_ ||_ ||_ ||_ dS)Nr8rT array_filters) r r rr=r>r rr5rrRr6rWr7)rr8docrTr9rXr:rrrrs      z_UpdateOp.__init__cCsLt|t|kr$|j|j|j|j|j|jf|j|j|j|j|j|jfkStSr$)r%r5rrRr6rWr7r&r'rrrr(s"z_UpdateOp.__eq__cCr)r$rr'rrrr*(r+z_UpdateOp.__ne__cCs&d|jj|j|j|j|j|j|jfS)Nz%s(%r, %r, %r, %r, %r, %r))rUr,r5rrRr6rWr7r!rrrr"+sz_UpdateOp.__repr__N) r,r-r.r/r0rr(r*r"rrrrrVs rVceZdZdZdZ    ddeeefdeeeefe fde de e d e e eeefd e ed dffd d ZddZZS) UpdateOnez#Represents an update_one operation.rFNr8updaterTr9rXr:rctt|||||||dS)aRepresents an update_one operation. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `filter`: A query that matches the document to update. - `update`: The modifications to apply. - `upsert` (optional): If ``True``, perform an insert if no documents match the filter. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `array_filters` (optional): A list of filters specifying which array elements an update should apply. - `hint` (optional): An index to use to support the query predicate specified either by its string name, or in the same format as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``). This option is only supported on MongoDB 4.2 and above. .. versionchanged:: 3.11 Added the `hint` option. .. versionchanged:: 3.9 Added the ability to accept a pipeline as the `update`. .. versionchanged:: 3.6 Added the `array_filters` option. .. versionchanged:: 3.5 Added the `collation` option. N)superr[rrr8r\rTr9rXr:rUrrr<&zUpdateOne.__init__c C(|j|j|jd|j|j|j|jddS)rFr9rXr:NZ add_updater5rrRr6rWr7rrrrr d zUpdateOne._add_to_bulkFNNNr,r-r.r/r0rr>rr rr1rrrrNrr __classcell__rrr`rr[7. (r[crZ) UpdateManyz$Represents an update_many operation.rFNr8r\rTr9rXr:rcr])aCreate an UpdateMany instance. For use with :meth:`~pymongo.collection.Collection.bulk_write`. :Parameters: - `filter`: A query that matches the documents to update. - `update`: The modifications to apply. - `upsert` (optional): If ``True``, perform an insert if no documents match the filter. - `collation` (optional): An instance of :class:`~pymongo.collation.Collation`. - `array_filters` (optional): A list of filters specifying which array elements an update should apply. - `hint` (optional): An index to use to support the query predicate specified either by its string name, or in the same format as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``). This option is only supported on MongoDB 4.2 and above. .. versionchanged:: 3.11 Added the `hint` option. .. versionchanged:: 3.9 Added the ability to accept a pipeline as the `update`. .. versionchanged:: 3.6 Added the `array_filters` option. .. versionchanged:: 3.5 Added the `collation` option. N)r^rjrr_r`rrrvrazUpdateMany.__init__c Crb)rTrcNrdrrrrr rezUpdateMany._add_to_bulkrfrgrrr`rrjqrirjc@sDeZdZdZdZdededdfddZede e effd d Z dS) IndexModelzRepresents an index to create.)Z __documentkeyskwargsrNcKsXt|}d|vrt||d<t||d<t|dd}||_|dur*||jd<dSdS)aT Create an Index instance. For use with :meth:`~pymongo.collection.Collection.create_indexes`. Takes either a single key or a list of (key, direction) pairs. The key(s) must be an instance of :class:`basestring` (:class:`str` in python 3), and the direction(s) must be one of (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, :data:`~pymongo.GEO2D`, :data:`~pymongo.GEOSPHERE`, :data:`~pymongo.HASHED`, :data:`~pymongo.TEXT`). Valid options include, but are not limited to: - `name`: custom name to use for this index - if none is given, a name will be generated. - `unique`: if ``True``, creates a uniqueness constraint on the index. - `background`: if ``True``, this index should be created in the background. - `sparse`: if ``True``, omit from the index any documents that lack the indexed field. - `bucketSize`: for use with geoHaystack indexes. Number of documents to group together within a certain proximity to a given longitude and latitude. - `min`: minimum value for keys in a :data:`~pymongo.GEO2D` index. - `max`: maximum value for keys in a :data:`~pymongo.GEO2D` index. - `expireAfterSeconds`: Used to create an expiring (TTL) collection. MongoDB will automatically delete documents from this collection after seconds. The indexed field must be a UTC datetime or the data will not expire. - `partialFilterExpression`: A document that specifies a filter for a partial index. - `collation`: An instance of :class:`~pymongo.collation.Collation` that specifies the collation to use. - `wildcardProjection`: Allows users to include or exclude specific field paths from a `wildcard index`_ using the { "$**" : 1} key pattern. Requires MongoDB >= 4.2. - `hidden`: if ``True``, this index will be hidden from the query planner and will not be evaluated as part of query plan selection. Requires MongoDB >= 4.4. See the MongoDB documentation for a full list of supported options by server version. :Parameters: - `keys`: a single key or a list of (key, direction) pairs specifying the index to create - `**kwargs` (optional): any additional index creation options (see the above list) should be passed as keyword arguments .. versionchanged:: 3.11 Added the ``hidden`` option. .. versionchanged:: 3.2 Added the ``partialFilterExpression`` option to support partial indexes. .. _wildcard index: https://mongodb.com/docs/master/core/index-wildcard/ namekeyr9N)rrrr pop_IndexModel__document)rrlrmr9rrrrs=  zIndexModel.__init__cCs|jS)zUAn index document suitable for passing to the createIndexes command. )rqr!rrrrszIndexModel.document) r,r-r.r/r0rNrrpropertyrr>rrrrrrks FrkN)'r/typingrrrrrrrr Zpymongor Zpymongo.collationr Zpymongo.commonr r rZpymongo.helpersrrrZpymongo.typingsrrrobjectrr>intZ _IndexListrNr3rPrQrVr[rjrkrrrrs"(  " 88Q9::