How do I get the number of affected documents in AQL?
Given a query like this:
FOR u IN users
FILTER u.active == true
UPDATE u WITH { numberOfLogins: 0 } IN users
How can I get the number of affected documents?
The query itself will not return any documents, but can provide the number of documents updated. The following example shows how to do it in the ArangoShell:
var query = "FOR u IN users FILTER u.active == true UPDATE u WITH { numberOfLogins: 0 } IN users";
var stmt = db._createStatement(query);
var result = stmt.execute();
var stats = result.getExtra().stats;
print(stats);
In my case that returned something like the following:
{
"writesExecuted" : 50,
"writesIgnored" : 0,
"scannedFull" : 100,
"scannedIndex" : 0
}
writesExecuted
is probably the figure you are after. It indicates how many document updates were done. How to get to the figure from language-specific drivers might be different (likely depends on the language and driver), but ArangoDB's HTTP API that all drivers use provides this figure.