Closed DasLukas closed 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.
status
is the answer array directly from the endpointok
is a list of all documents as Document
instances that were successfully savederror
is a list of all documents as Document
instances that couldn't be savedPlease note that the Document
instances in ok
and error
are the same as provided within the with
-context.
Thank you for your fast answer. The hint with the test cases helps extremely.
I'll keep this issue open, so I'll eventually write some documentation
I wonder how do use BulkOperstions (respectively db.update_docs()) the right way?
The documentation is not complete on this topic.