MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / bulk_write

Method bulk_write

pymongo/asynchronous/collection.py:699–794  ·  view source on GitHub ↗

Send a batch of write operations to the server. Requests are passed as a list of write operation instances ( :class:`~pymongo.operations.InsertOne`, :class:`~pymongo.operations.UpdateOne`, :class:`~pymongo.operations.UpdateMany`, :class:`~pymongo.operations.R

(
        self,
        requests: Sequence[_WriteOp[_DocumentType]],
        ordered: bool = True,
        bypass_document_validation: Optional[bool] = None,
        session: Optional[AsyncClientSession] = None,
        comment: Optional[Any] = None,
        let: Optional[Mapping[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

697
698 @_csot.apply
699 async def bulk_write(
700 self,
701 requests: Sequence[_WriteOp[_DocumentType]],
702 ordered: bool = True,
703 bypass_document_validation: Optional[bool] = None,
704 session: Optional[AsyncClientSession] = None,
705 comment: Optional[Any] = None,
706 let: Optional[Mapping[str, Any]] = None,
707 ) -> BulkWriteResult:
708 """Send a batch of write operations to the server.
709
710 Requests are passed as a list of write operation instances (
711 :class:`~pymongo.operations.InsertOne`,
712 :class:`~pymongo.operations.UpdateOne`,
713 :class:`~pymongo.operations.UpdateMany`,
714 :class:`~pymongo.operations.ReplaceOne`,
715 :class:`~pymongo.operations.DeleteOne`, or
716 :class:`~pymongo.operations.DeleteMany`).
717
718 >>> async for doc in db.test.find({}):
719 ... print(doc)
720 ...
721 {'x': 1, '_id': ObjectId('54f62e60fba5226811f634ef')}
722 {'x': 1, '_id': ObjectId('54f62e60fba5226811f634f0')}
723 >>> # DeleteMany, UpdateOne, and UpdateMany are also available.
724 ...
725 >>> from pymongo import InsertOne, DeleteOne, ReplaceOne
726 >>> requests = [InsertOne({'y': 1}), DeleteOne({'x': 1}),
727 ... ReplaceOne({'w': 1}, {'z': 1}, upsert=True)]
728 >>> result = await db.test.bulk_write(requests)
729 >>> result.inserted_count
730 1
731 >>> result.deleted_count
732 1
733 >>> result.modified_count
734 0
735 >>> result.upserted_ids
736 {2: ObjectId('54f62ee28891e756a6e1abd5')}
737 >>> async for doc in db.test.find({}):
738 ... print(doc)
739 ...
740 {'x': 1, '_id': ObjectId('54f62e60fba5226811f634f0')}
741 {'y': 1, '_id': ObjectId('54f62ee2fba5226811f634f1')}
742 {'z': 1, '_id': ObjectId('54f62ee28891e756a6e1abd5')}
743
744 :param requests: A list of write operations (see examples above).
745 :param ordered: If ``True`` (the default) requests will be
746 performed on the server serially, in the order provided. If an error
747 occurs all remaining operations are aborted. If ``False`` requests
748 will be performed on the server in arbitrary order, possibly in
749 parallel, and all operations will be attempted.
750 :param bypass_document_validation: (optional) If ``True``, allows the
751 write to opt-out of document level validation. Default is
752 ``False``.
753 :param session: a
754 :class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
755 :param comment: A user-provided comment to attach to this
756 command.

Callers 1

rewrap_many_data_keyMethod · 0.45

Calls 5

_AsyncBulkClass · 0.90
BulkWriteResultClass · 0.90
_write_concern_forMethod · 0.80
_add_to_bulkMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected