1
更新:找到解决方案。 ARANGODB集群不支持交易。它仅支持一次性实例。ArangoDB事务不会在出错时回滚
我想使用arangoJS库的交易功能。我将介绍的函数只是一个插入两条记录的虚拟函数,然后尝试获取不存在的文档。获取不存在的文档会生成错误,并且事务必须回滚。确实,在尝试获取不存在的文档后会生成错误。但是,数据库不会回滚,并且两个插入的文档仍然插入到数据库中。有谁知道如何解决它?
"updateCustomer" : function (options, cb) {
const action = String(function (params) {
// This code will be executed inside ArangoDB!
const db = require('@arangodb').db;
const aql = require('@arangodb').aql;
const customer = db._collection('customer');
try{
//insert two documents
db._query(aql`INSERT ${params.user} INTO ${customer} Return NEW`);
db._query(aql`INSERT ${params.customer} INTO ${customer} Return NEW`);
//Get a document that doesn't exist
customer.document('does-not-exist');
}catch(e){
throw new Error("Everything is bad");
}
});
let opts = {
collections : {
read : ["customer"],
write : ["customer"]
},
action : action,
params : {user: options, customer: options},
lockTimeout : 5
};
Arango.transaction(opts,(err, result) => {
console.log("err: " + err);
console.log("result: " + JSON.stringify(result));
return cb(err, result);
});
}
"transaction" : function (options, cb) {
utils.dbConnect().transaction(options.collections, options.action, options.params, options.lockTimeout, cb);
}
更新:我试过这个事务在单个实例ArangoDB,它的工作。但是,它不适用于群集。是否不支持ArangoDB群集上的事务?