bulk – The bulk write operations interface

The bulk write operations interface.

New in version 2.7.

  • class pymongo.bulk.BulkOperationBuilder(collection, ordered=True, bypass_document_validation=False)
  • DEPRECATED: Initialize a new BulkOperationBuilder instance.

Parameters:

  • collection: A Collection instance.
  • ordered (optional): If True all operations will be executedserially, in the order provided, and the entire execution willabort on the first error. If False operations will be executedin arbitrary order (possibly in parallel on the server), reportingany errors that occurred after attempting all operations. Defaultsto True.
  • bypass_document_validation: (optional) If True, allows thewrite to opt-out of document level validation. Default isFalse.

Note

bypass_document_validation requires server version>= 3.2

Changed in version 3.5: Deprecated. Use bulk_write()instead.

Changed in version 3.2: Added bypass_document_validation support

  • execute(write_concern=None)
  • Execute all provided operations.

Parameters:

  1. - write_concern (optional): the write concern for this bulkexecution.
  • find(selector, collation=None)
  • Specify selection criteria for bulk operations.

Parameters:

  1. - _selector_ (dict): the selection criteria for updateand remove operations.
  2. - _collation_ (optional): An instance of[<code>Collation</code>]($f10fec00031f6158.md#pymongo.collation.Collation). This option is onlysupported on MongoDB 3.4 and above.Returns:
  3. - A [<code>BulkWriteOperation</code>](https://api.mongodb.com/python/current/api/pymongo/#pymongo.bulk.BulkWriteOperation) instance, used to addupdate and remove operations to this bulk operation.

Changed in version 3.4: Added the collation option.

  • insert(document)
  • Insert a single document.

Parameters:

  1. - _document_ (dict): the document to insert

See also

Why does PyMongo add an _id field to all of my documents?

  • class pymongo.bulk.BulkUpsertOperation(selector, bulk, collation)
  • An interface for adding upsert operations.

    • replaceone(_replacement)
    • Replace one entire document matching the selector criteria.

Parameters:

  1. - _replacement_ (dict): the replacement document
  • update(update)
  • Update all documents matching the selector.

Parameters:

  1. - _update_ (dict): the update operations to apply
  • updateone(_update)
  • Update one document matching the selector.

Parameters:

  1. - _update_ (dict): the update operations to apply
  • class pymongo.bulk.BulkWriteOperation(selector, bulk, collation)
  • An interface for adding update or remove operations.

    • remove()
    • Remove all documents matching the selector criteria.

    • remove_one()

    • Remove a single document matching the selector criteria.

    • replaceone(_replacement)

    • Replace one entire document matching the selector criteria.

Parameters:

  1. - _replacement_ (dict): the replacement document
  • update(update)
  • Update all documents matching the selector criteria.

Parameters:

  1. - _update_ (dict): the update operations to apply
  • updateone(_update)
  • Update one document matching the selector criteria.

Parameters:

  1. - _update_ (dict): the update operations to apply
  • upsert()
  • Specify that all chained update operations should beupserts.

Returns:

  1. - A [<code>BulkUpsertOperation</code>](https://api.mongodb.com/python/current/api/pymongo/#pymongo.bulk.BulkUpsertOperation) instance, used to addupdate operations to this bulk operation.