How to prevent ArangoDB from throwing an exception during a transaction when looking for a specific document that may not exist at this point?
Nodejs sends the transaction in one block to ArangoDb, where it is processed. It's fine. I want to upload all the math to the server.
During the transaction, I want to look at a specific collection and check if the document exists, if the document can be found, and then get the "balance" field, but if the document is not found or its field, then I do not want to throw an exception and do not want to stop the current transaction. On the contrary, I want to continue the transaction much more, and we will assign the string "0" to the oldBalance variable.
(for your information: there is a write lock for the collection: "user" is indicated on the nodeJS side) and here you see part of the transaction code sent to ArangoDB:
var db = require('internal').db;
var accountdoc = db.user.document('Johnny04');
this throws an exception if this document is not found. At that time, the user probably did not have an entry in the collection. In this case, we want to consider its balance line '0'. But, unfortunately, an exception has already been thrown. I would much like to do the following:
if (accountdoc.error==true){
var oldBalance='0';
var documentExists = false;
} else {
var oldBalance=accountdoc.balance;
var documentExists = true;
var documentExistsID = accountdoc._id;
}
source
share