operations – Operation class definitions
For use with .
Parameters:
- filter: A query that matches the documents to delete.
- collation (optional): An instance of
Collation
. This option is onlysupported on MongoDB 3.4 and above.
Changed in version 3.5: Added the collation option.
- class
pymongo.operations.
DeleteOne
(filter, collation=None) - Create a DeleteOne instance.
For use with bulk_write()
.
Parameters:
- filter: A query that matches the document to delete.
- collation (optional): An instance of. This option is onlysupported on MongoDB 3.4 and above.
Changed in version 3.5: Added the collation option.
For use with .
Takes either a single key or a list of (key, direction) pairs.The key(s) must be an instance of basestring
(str
in python 3), and the direction(s) must be one of(, DESCENDING
,, GEOHAYSTACK
,, HASHED
,).
See the MongoDB documentation for a full list of supported options byserver version.
Parameters:
- keys: a single key or a list of (key, direction)pairs specifying the index to create
- **kwargs (optional): any additional index creationoptions (see the above list) should be passed as keywordarguments
Changed in version 3.2: Added partialFilterExpression to support partial indexes.
- class
pymongo.operations.
InsertOne
(document) - Create an InsertOne instance.
For use with bulk_write()
.
Parameters:
- document: The document to insert. If the document is missing an_id field one will be added.
- class
ReplaceOne
(filter, replacement, upsert=False, collation=None) - Create a ReplaceOne instance.
For use with bulk_write()
.
Parameters:
- filter: A query that matches the document to replace.
- upsert (optional): If
True
, perform an insert if no documentsmatch the filter. - collation (optional): An instance of. This option is onlysupported on MongoDB 3.4 and above.
Changed in version 3.5: Added the collation option.
- class
pymongo.operations.
UpdateMany
(filter, update, upsert=False, collation=None, array_filters=None) - Create an UpdateMany instance.
Parameters:
- filter: A query that matches the documents to update.
- update: The modifications to apply.
- upsert (optional): If
True
, perform an insert if no documentsmatch the filter. - collation (optional): An instance of. This option is onlysupported on MongoDB 3.4 and above.
- array_filters (optional): A list of filters specifying whicharray elements an update should apply. Requires MongoDB 3.6+.
Changed in version 3.9: Added the ability to accept a pipeline as the update.
Changed in version 3.6: Added the array_filters option.
Changed in version 3.5: Added the collation option.
- class
pymongo.operations.
UpdateOne
(filter, update, upsert=False, collation=None, array_filters=None) - Represents an update_one operation.
For use with .
Parameters:
- filter: A query that matches the document to update.
- update: The modifications to apply.
- upsert (optional): If
True
, perform an insert if no documentsmatch the filter. - collation (optional): An instance of
Collation
. This option is onlysupported on MongoDB 3.4 and above.
Changed in version 3.9: Added the ability to accept a pipeline as the update.
Changed in version 3.6: Added the array_filters option.