@@ -1288,9 +1288,8 @@ async def replace_many(
1288
1288
(returns exception object).
1289
1289
1290
1290
Args:
1291
- documents (list): New documents to replace the old ones. If an item
1292
- contains the "_key" or "_id" field, the value is used as the key
1293
- of the new document (otherwise it is auto-generated).
1291
+ documents (list): New documents to replace the old ones. An item must
1292
+ contain the "_key" or "_id" field.
1294
1293
wait_for_sync (bool | None): Wait until documents have been synced to disk.
1295
1294
ignore_revs (bool | None): If this is set to `False`, then any `_rev`
1296
1295
attribute given in a body document is taken as a precondition. The
@@ -1299,8 +1298,7 @@ async def replace_many(
1299
1298
return_new (bool | None): Additionally return the complete new document
1300
1299
under the attribute `new` in the result.
1301
1300
return_old (bool | None): Additionally return the complete old document
1302
- under the attribute `old` in the result. Only available if the
1303
- `overwrite` option is used.
1301
+ under the attribute `old` in the result.
1304
1302
silent (bool | None): If set to `True`, an empty object is returned as
1305
1303
response if all document operations succeed. No meta-data is returned
1306
1304
for the created documents. If any of the operations raises an error,
@@ -1309,8 +1307,7 @@ async def replace_many(
1309
1307
in-memory index caches if document operations affect the edge index
1310
1308
or cache-enabled persistent indexes.
1311
1309
version_attribute (str | None): Support for simple external versioning to
1312
- document operations. Only applicable if **overwrite** is set to `True`
1313
- or **overwrite_mode** is set to "update" or "replace".
1310
+ document operations.
1314
1311
1315
1312
Returns:
1316
1313
list: Documents metadata (e.g. document id, key, revision) and
@@ -1353,3 +1350,100 @@ def response_handler(
1353
1350
return self .deserializer .loads_many (resp .raw_body )
1354
1351
1355
1352
return await self ._executor .execute (request , response_handler )
1353
+
1354
+ async def update_many (
1355
+ self ,
1356
+ documents : Sequence [T ],
1357
+ wait_for_sync : Optional [bool ] = None ,
1358
+ ignore_revs : Optional [bool ] = None ,
1359
+ return_new : Optional [bool ] = None ,
1360
+ return_old : Optional [bool ] = None ,
1361
+ silent : Optional [bool ] = None ,
1362
+ keep_null : Optional [bool ] = None ,
1363
+ merge_objects : Optional [bool ] = None ,
1364
+ refill_index_caches : Optional [bool ] = None ,
1365
+ version_attribute : Optional [str ] = None ,
1366
+ ) -> Result [Jsons ]:
1367
+ """Insert multiple documents.
1368
+
1369
+ Note:
1370
+ If updating a document fails, the exception is not raised but
1371
+ returned as an object in the "errors" list. It is up to you to
1372
+ inspect the list to determine which documents were updated
1373
+ successfully (returned as document metadata) and which were not
1374
+ (returned as exception object).
1375
+
1376
+ Args:
1377
+ documents (list): Documents to update. An item must contain the "_key" or
1378
+ "_id" field.
1379
+ wait_for_sync (bool | None): Wait until documents have been synced to disk.
1380
+ ignore_revs (bool | None): If this is set to `False`, then any `_rev`
1381
+ attribute given in a body document is taken as a precondition. The
1382
+ document is only updated if the current revision is the one
1383
+ specified.
1384
+ return_new (bool | None): Additionally return the complete new document
1385
+ under the attribute `new` in the result.
1386
+ return_old (bool | None): Additionally return the complete old document
1387
+ under the attribute `old` in the result.
1388
+ silent (bool | None): If set to `True`, an empty object is returned as
1389
+ response if all document operations succeed. No meta-data is returned
1390
+ for the created documents. If any of the operations raises an error,
1391
+ an array with the error object(s) is returned.
1392
+ keep_null (bool | None): If set to `True`, fields with value None are
1393
+ retained in the document. Otherwise, they are removed completely.
1394
+ Applies only when **overwrite_mode** is set to "update"
1395
+ (update-insert).
1396
+ merge_objects (bool | None): If set to `True`, sub-dictionaries are merged
1397
+ instead of the new one overwriting the old one. Applies only when
1398
+ **overwrite_mode** is set to "update" (update-insert).
1399
+ refill_index_caches (bool | None): Whether to add new entries to
1400
+ in-memory index caches if document operations affect the edge index
1401
+ or cache-enabled persistent indexes.
1402
+ version_attribute (str | None): Support for simple external versioning to
1403
+ document operations.
1404
+
1405
+ Returns:
1406
+ list: Documents metadata (e.g. document id, key, revision) and
1407
+ errors or just errors if **silent** is set to `True`.
1408
+
1409
+ Raises:
1410
+ DocumentUpdateError: If update fails.
1411
+
1412
+ References:
1413
+ - `update-multiple-documents <https://docs.arangodb.com/stable/develop/http-api/documents/#update-multiple-documents>`__
1414
+ """ # noqa: E501
1415
+ params : Params = {}
1416
+ if wait_for_sync is not None :
1417
+ params ["waitForSync" ] = wait_for_sync
1418
+ if ignore_revs is not None :
1419
+ params ["ignoreRevs" ] = ignore_revs
1420
+ if return_new is not None :
1421
+ params ["returnNew" ] = return_new
1422
+ if return_old is not None :
1423
+ params ["returnOld" ] = return_old
1424
+ if silent is not None :
1425
+ params ["silent" ] = silent
1426
+ if keep_null is not None :
1427
+ params ["keepNull" ] = keep_null
1428
+ if merge_objects is not None :
1429
+ params ["mergeObjects" ] = merge_objects
1430
+ if refill_index_caches is not None :
1431
+ params ["refillIndexCaches" ] = refill_index_caches
1432
+ if version_attribute is not None :
1433
+ params ["versionAttribute" ] = version_attribute
1434
+
1435
+ request = Request (
1436
+ method = Method .PATCH ,
1437
+ endpoint = f"/_api/document/{ self .name } " ,
1438
+ data = self ._doc_serializer .dumps (documents ),
1439
+ params = params ,
1440
+ )
1441
+
1442
+ def response_handler (
1443
+ resp : Response ,
1444
+ ) -> Jsons :
1445
+ if not resp .is_success :
1446
+ raise DocumentUpdateError (resp , request )
1447
+ return self .deserializer .loads_many (resp .raw_body )
1448
+
1449
+ return await self ._executor .execute (request , response_handler )
0 commit comments