Bulk.find.update()

Does bulk update create a single database connection for multiple update operations?

E.g
I have collection A
where I need to update 2 fields of A collection’s Document. But due to the difference of relation of update with query i need to create a and b update operations. Will bulk update send my a,b operations in a single db connection from my client app ?

Hi @Md_Mahadi_Hossain

The bulk functions take a list of write operations, you can imagine it as a list or array of these distinct operations (create, update, delete). You can have many different update operations a single bulk call as long as they are only being performed on a single collection (e.g. collection A).

In your example, you would add both the ‘a’ and the ‘b’ update operations to the list for that set of Bulk Operations. You would then execute that list of operations, it will be sent in a single call across to your database from your application. The operations will then be executed against the database (they may be ordered or in parallel (unordered) depending on the type BulkOP builder you used).

The operations should be held in that one list of operations which is sent as a single item across a single db connection.

Does bulk update create a single database connection for multiple update operations?

The bulk update operation itself does not create the database connection and you will need to do this elsewhere in your code.

There are more details in the docs page here - https://docs.mongodb.com/manual/reference/method/Bulk/
An example of using the Bulk API for PyMongo for Python can be seen in it’s docs here - https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.bulk_write

Hopefully, this helps clarify your question.

1 Like