metricq / aiocouch

🛋 An asynchronous client library for CouchDB 2.x and 3.x
https://aiocouch.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
29 stars 10 forks source link

Documentation of BulkOperation #33

Closed DasLukas closed 3 years ago

DasLukas commented 3 years ago

I wonder how do use BulkOperstions (respectively db.update_docs()) the right way?

The documentation is not complete on this topic.

bmario commented 3 years ago

I'm sorry that the documentation is lacking in this area. There are some test cases with the bulk operation here.

The general idea is to use the update_docs() and create_docs methods of a Database instance to get hold of the context manager. Hence, it would be best to use, for example, async with your_database.update_docs(...) as bulk_docs:. The parameter to the method is a list of affected document ids. And the create argument, which defines the behavior in case the update_docs() is given an id, which doesn't exist.

You apply all changes that shall be part of the bulk operation within the with-context. To submit the bulk operation, leave the with-context. Once outside of the context, the bulk operation will have finished, and you can use the with-target, bulk_docs in the above example to figure out the result of the bulk operation. Under the hood, the bulk operations use the _bulk_docs endpoint. The with-target now has several members.

Please note that the Document instances in ok and error are the same as provided within the with-context.

DasLukas commented 3 years ago

Thank you for your fast answer. The hint with the test cases helps extremely.

bmario commented 3 years ago

I'll keep this issue open, so I'll eventually write some documentation