operations – Operation class definitions

    class pymongo.operations.DeleteMany(filter, collation=None, hint=None)

    Create a DeleteMany instance.

    For use with bulk_write().

    Changed in version 3.11: Added the hint option.

    Changed in version 3.5: Added the collation option.

    class pymongo.operations.DeleteOne(filter, collation=None, hint=None)

    Create a DeleteOne instance.

    For use with .

    Parameters:
    • filter: A query that matches the document to delete.
    • collation (optional): An instance of Collation. This option is only supported on MongoDB 3.4 and above.
    • 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 (e.g. [(‘field’, ASCENDING)]). This option is only supported on MongoDB 4.4 and above.

    Changed in version 3.11: Added the hint option.

    Changed in version 3.5: Added the collation option.

    class pymongo.operations.IndexModel(keys, \*kwargs*)

    Create an Index instance.

    For use with create_indexes().

    Valid options include, but are not limited to:

    See the MongoDB documentation for a full list of supported options by server version.

    Changed in version 3.11: Added the hidden option.

    Changed in version 3.2: Added the partialFilterExpression option to support partial indexes.

    • document

      An index document suitable for passing to the createIndexes command.

    class pymongo.operations.InsertOne(document)

    Create an InsertOne instance.

    For use with .

    Parameters:
    • document: The document to insert. If the document is missing an _id field one will be added.

    class (filter, replacement, upsert=False, collation=None, hint=None)

    Create a ReplaceOne instance.

    For use with bulk_write().

    Changed in version 3.11: Added the hint option.

    class pymongo.operations.UpdateMany(filter, update, upsert=False, collation=None, array_filters=None, hint=None)

    Create an UpdateMany instance.

    For use with .

    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 Collation. This option is only supported on MongoDB 3.4 and above.
    • array_filters (optional): A list of filters specifying which array elements an update should apply. Requires MongoDB 3.6+.
    • 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 (e.g. [(‘field’, ASCENDING)]). This option is only supported on MongoDB 4.2 and above.

    Changed in version 3.11: Added the hint option.

    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, hint=None)

    Represents an update_one operation.

    For use with bulk_write().

    Changed in version 3.11: Added the hint option.

    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.