当我查看交易文档时,我遇到了这个例子:
var tx = session.beginTransaction();
tx.run("MERGE (bob:Person {name : {nameParam} }) RETURN bob.name AS name", {nameParam: 'Bob'})
.subscribe({
onNext: function (record) {
console.log(record.get('name'));
},
onCompleted: function () {
session.close();
},
onError: function (error) {
console.log(error);
}
});
//decide if the transaction should be committed or rolled back
var success = false;
if (success) {
tx.commit()
.subscribe({
onCompleted: function () {
// this transaction is now committed
},
onError: function (error) {
console.log(error);
}
});
} else {
//transaction is rolled black and nothing is created in the database
console.log('rolled back');
tx.rollback();
}
但是在上面的代码片段中,它似乎并没有改变success
我的意思是它如何确定事务是否成功执行,success
变量根本没有改变值。