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 executed serially, in the order provided, and the entire execution will abort on the first error. IfFalse
operations will be executed in arbitrary order (possibly in parallel on the server), reporting any errors that occurred after attempting all operations. Defaults toTrue
.bypass_document_validation: (optional) If
True
, allows the write 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
- write_concern (optional): the write concern for this bulk execution.
find(selector, collation=None)
Specify selection criteria for bulk operations.
Parameters
selector (dict): the selection criteria for update and remove operations.
collation (optional): An instance of Collation. This option is only supported on MongoDB 3.4 and above.
Returns
- A BulkWriteOperation instance, used to add update and remove operations to this bulk operation.
Changed in version 3.4: Added the collation option.
insert(document)
Insert a single document.
Parameters
- document (dict): the document to insert
See also
class pymongo.bulk.BulkUpsertOperation(selector, bulk, collation)
An interface for adding upsert operations.
replace_one(replacement)
Replace one entire document matching the selector criteria.
Parameters
- replacement (dict): the replacement document
update(update)
Update all documents matching the selector.
Parameters
- update (dict): the update operations to apply
update_one(update)
Update one document matching the selector.
Parameters
- 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.
replace_one(replacement)
Replace one entire document matching the selector criteria.
Parameters
- replacement (dict): the replacement document
update(update)
Update all documents matching the selector criteria.
Parameters
- update (dict): the update operations to apply
update_one(update)
Update one document matching the selector criteria.
Parameters
- update (dict): the update operations to apply
upsert()
Specify that all chained update operations should be upserts.
Returns
- A BulkUpsertOperation instance, used to add update operations to this bulk operation.