@@ -1177,7 +1177,7 @@ async def insert_many(
1177
1177
merge_objects : Optional [bool ] = None ,
1178
1178
refill_index_caches : Optional [bool ] = None ,
1179
1179
version_attribute : Optional [str ] = None ,
1180
- ) -> Result [Optional [ Jsons ] ]:
1180
+ ) -> Result [Jsons ]:
1181
1181
"""Insert multiple documents.
1182
1182
1183
1183
Note:
@@ -1213,15 +1213,15 @@ async def insert_many(
1213
1213
instead of the new one overwriting the old one. Applies only when
1214
1214
**overwrite_mode** is set to "update" (update-insert).
1215
1215
refill_index_caches (bool | None): Whether to add new entries to
1216
- in-memory index caches if document insertions affect the edge index
1216
+ in-memory index caches if document operations affect the edge index
1217
1217
or cache-enabled persistent indexes.
1218
1218
version_attribute (str | None): Support for simple external versioning to
1219
1219
document operations. Only applicable if **overwrite** is set to `True`
1220
1220
or **overwrite_mode** is set to "update" or "replace".
1221
1221
1222
1222
Returns:
1223
- None | list: Documents metadata (e.g. document id, key, revision) and
1224
- errors or `None` if **silent** is set to `True`.
1223
+ list: Documents metadata (e.g. document id, key, revision) and
1224
+ errors or just errors if **silent** is set to `True`.
1225
1225
1226
1226
Raises:
1227
1227
DocumentInsertError: If insertion fails.
@@ -1266,3 +1266,90 @@ def response_handler(
1266
1266
return self .deserializer .loads_many (resp .raw_body )
1267
1267
1268
1268
return await self ._executor .execute (request , response_handler )
1269
+
1270
+ async def replace_many (
1271
+ self ,
1272
+ documents : Sequence [T ],
1273
+ wait_for_sync : Optional [bool ] = None ,
1274
+ ignore_revs : Optional [bool ] = None ,
1275
+ return_new : Optional [bool ] = None ,
1276
+ return_old : Optional [bool ] = None ,
1277
+ silent : Optional [bool ] = None ,
1278
+ refill_index_caches : Optional [bool ] = None ,
1279
+ version_attribute : Optional [str ] = None ,
1280
+ ) -> Result [Jsons ]:
1281
+ """Insert multiple documents.
1282
+
1283
+ Note:
1284
+ If replacing a document fails, the exception is not raised but
1285
+ returned as an object in the "errors" list. It is up to you to
1286
+ inspect the list to determine which documents were replaced
1287
+ successfully (returns document metadata) and which were not
1288
+ (returns exception object).
1289
+
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).
1294
+ wait_for_sync (bool | None): Wait until documents have been synced to disk.
1295
+ ignore_revs (bool | None): If this is set to `False`, then any `_rev`
1296
+ attribute given in a body document is taken as a precondition. The
1297
+ document is only replaced if the current revision is the one
1298
+ specified.
1299
+ return_new (bool | None): Additionally return the complete new document
1300
+ under the attribute `new` in the result.
1301
+ 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.
1304
+ silent (bool | None): If set to `True`, an empty object is returned as
1305
+ response if all document operations succeed. No meta-data is returned
1306
+ for the created documents. If any of the operations raises an error,
1307
+ an array with the error object(s) is returned.
1308
+ refill_index_caches (bool | None): Whether to add new entries to
1309
+ in-memory index caches if document operations affect the edge index
1310
+ or cache-enabled persistent indexes.
1311
+ 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".
1314
+
1315
+ Returns:
1316
+ list: Documents metadata (e.g. document id, key, revision) and
1317
+ errors or just errors if **silent** is set to `True`.
1318
+
1319
+ Raises:
1320
+ DocumentReplaceError: If replacing fails.
1321
+
1322
+ References:
1323
+ - `replace-multiple-documents <https://docs.arangodb.com/stable/develop/http-api/documents/#replace-multiple-documents>`__
1324
+ """ # noqa: E501
1325
+ params : Params = {}
1326
+ if wait_for_sync is not None :
1327
+ params ["waitForSync" ] = wait_for_sync
1328
+ if ignore_revs is not None :
1329
+ params ["ignoreRevs" ] = ignore_revs
1330
+ if return_new is not None :
1331
+ params ["returnNew" ] = return_new
1332
+ if return_old is not None :
1333
+ params ["returnOld" ] = return_old
1334
+ if silent is not None :
1335
+ params ["silent" ] = silent
1336
+ if refill_index_caches is not None :
1337
+ params ["refillIndexCaches" ] = refill_index_caches
1338
+ if version_attribute is not None :
1339
+ params ["versionAttribute" ] = version_attribute
1340
+
1341
+ request = Request (
1342
+ method = Method .PUT ,
1343
+ endpoint = f"/_api/document/{ self .name } " ,
1344
+ data = self ._doc_serializer .dumps (documents ),
1345
+ params = params ,
1346
+ )
1347
+
1348
+ def response_handler (
1349
+ resp : Response ,
1350
+ ) -> Jsons :
1351
+ if not resp .is_success :
1352
+ raise DocumentReplaceError (resp , request )
1353
+ return self .deserializer .loads_many (resp .raw_body )
1354
+
1355
+ return await self ._executor .execute (request , response_handler )
0 commit comments