"document.update:fail [ResourceUnavailable.TransactionConflict] Transaction is conflict, maybe resource operated by others. Please check your request, but if the problem persists, contact us.; at document.update api; "
云数据库的一个简单事务处理,代码如下:
const cmd = db.command;
const updtranscation = await db.startTransaction();
res = await updtranscation.collection('xinfo').doc(_id).update({
data: info
});
if(info.total_pay>0){
res = await updtranscation.collection("xaction").doc(info._id).update({
data:{
total_pay:cmd.inc(info.total_pay)
}
});
}
updtranscation.commit();