@@ -1179,7 +1179,7 @@ async def update_match(
1179
1179
Args:
1180
1180
filters (dict | None): Query filters.
1181
1181
body (dict): Full or partial document body with the updates.
1182
- limit (int | str | None): Maximum number of documents to return .
1182
+ limit (int | str | None): Maximum number of documents to update .
1183
1183
keep_none (bool | None): If set to `True`, fields with value `None` are
1184
1184
retained in the document. Otherwise, they are removed completely.
1185
1185
wait_for_sync (bool | None): Wait until operation has been synced to disk.
@@ -1198,8 +1198,6 @@ async def update_match(
1198
1198
if not (self ._is_none_or_int (limit ) or limit == "null" ):
1199
1199
raise ValueError ("limit parameter must be a non-negative int" )
1200
1200
1201
- # If the waitForSync parameter is not specified or set to false,
1202
- # then the collection’s default waitForSync behavior is applied.
1203
1201
sync = f", waitForSync: { wait_for_sync } " if wait_for_sync is not None else ""
1204
1202
query = f"""
1205
1203
FOR doc IN @@collection
@@ -1237,6 +1235,69 @@ def response_handler(resp: Response) -> int:
1237
1235
1238
1236
return await self ._executor .execute (request , response_handler )
1239
1237
1238
+ async def replace_match (
1239
+ self ,
1240
+ filters : Json ,
1241
+ body : T ,
1242
+ limit : Optional [int | str ] = None ,
1243
+ wait_for_sync : Optional [bool ] = None ,
1244
+ allow_dirty_read : Optional [bool ] = None ,
1245
+ ) -> Result [int ]:
1246
+ """Replace matching documents.
1247
+
1248
+ Args:
1249
+ filters (dict | None): Query filters.
1250
+ body (dict): New document body.
1251
+ limit (int | str | None): Maximum number of documents to replace.
1252
+ wait_for_sync (bool | None): Wait until operation has been synced to disk.
1253
+ allow_dirty_read (bool | None): Allow reads from followers in a cluster.
1254
+
1255
+ Returns:
1256
+ int: Number of documents that got replaced.
1257
+
1258
+ Raises:
1259
+ DocumentReplaceError: If replace fails.
1260
+ """
1261
+ if not self ._is_none_or_dict (filters ):
1262
+ raise ValueError ("filters parameter must be a dict" )
1263
+ if not (self ._is_none_or_int (limit ) or limit == "null" ):
1264
+ raise ValueError ("limit parameter must be a non-negative int" )
1265
+
1266
+ sync = f"waitForSync: { wait_for_sync } " if wait_for_sync is not None else ""
1267
+ query = f"""
1268
+ FOR doc IN @@collection
1269
+ { self ._build_filter_conditions (filters )}
1270
+ { f"LIMIT { limit } " if limit is not None else "" }
1271
+ REPLACE doc WITH @body IN @@collection
1272
+ { f"OPTIONS {{ { sync } }}" if sync else "" }
1273
+ """ # noqa: E201 E202
1274
+ bind_vars = {
1275
+ "@collection" : self .name ,
1276
+ "body" : body ,
1277
+ }
1278
+ data = {"query" : query , "bindVars" : bind_vars }
1279
+ headers : RequestHeaders = {}
1280
+ if allow_dirty_read is not None :
1281
+ if allow_dirty_read is True :
1282
+ headers ["x-arango-allow-dirty-read" ] = "true"
1283
+ else :
1284
+ headers ["x-arango-allow-dirty-read" ] = "false"
1285
+
1286
+ request = Request (
1287
+ method = Method .POST ,
1288
+ endpoint = "/_api/cursor" ,
1289
+ data = self .serializer .dumps (data ),
1290
+ headers = headers ,
1291
+ )
1292
+
1293
+ def response_handler (resp : Response ) -> int :
1294
+ if resp .is_success :
1295
+ result = self .deserializer .loads (resp .raw_body )
1296
+ return cast (int , result ["extra" ]["stats" ]["writesExecuted" ])
1297
+ raise DocumentReplaceError (resp , request )
1298
+
1299
+ return await self ._executor .execute (request , response_handler )
1300
+
1240
1301
async def insert_many (
1241
1302
self ,
1242
1303
documents : Sequence [T ],
0 commit comments