operations – Operation class definitions
Operation class definitions.
For use with bulk_write()
.
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.
For use with bulk_write()
.
Parameters:
- filter: A query that matches the document 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.
For use with create_indexes()
.
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(ASCENDING
, DESCENDING
,GEO2D
, GEOHAYSTACK
,GEOSPHERE
, HASHED
,TEXT
).
Valid options include, but are not limited to:
- name: custom name to use for this index - if none isgiven, a name will be generated.
- unique: if
True
creates a uniqueness constraint on the index.- background: if
True
this index should be created in thebackground.- sparse: if
True
, omit from the index any documents that lackthe indexed field.- bucketSize: for use with geoHaystack indexes.Number of documents to group together within a certain proximityto a given longitude and latitude.
- min: minimum value for keys in a
GEO2D
index.- max: maximum value for keys in a
GEO2D
index.- expireAfterSeconds: <int> Used to create an expiring (TTL)collection. MongoDB will automatically delete documents fromthis collection after <int> seconds. The indexed field mustbe a UTC datetime or the data will not expire.
- partialFilterExpression: A document that specifies a filter fora partial index. Requires server version >= 3.2.
- collation: An instance of
Collation
that specifies the collation to use in MongoDB >= 3.4.- wildcardProjection: Allows users to include or exclude specificfield paths from a wildcard index using the { “$**” : 1} keypattern. Requires server version >= 4.2.
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.
For use with bulk_write()
.
Parameters:
- document: The document to insert. If the document is missing an_id field one will be added.
- class
pymongo.operations.
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.
- replacement: The new document.
- 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.5: Added the collation option.
- class
pymongo.operations.
UpdateMany
(filter, update, upsert=False, collation=None, array_filters=None) - Create an UpdateMany instance.
For use with 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 documentsmatch the filter. - collation (optional): An instance of
Collation
. 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 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 documentsmatch the filter. - collation (optional): An instance of
Collation
. 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.