如何将event.data.data()
中的数据作为读取值传递给事务?
exports.runMyTransaction = functions.firestore
.doc('/myCollection/{myId}').onWrite((event) => {
// In this transaction, I want to pass event instead of cityRef
var transaction = db.runTransaction(t => {
return t.get(cityRef)
.then(doc => {
// doc should contain the event object
var newPopulation = doc.data().population + 1;
t.update(cityRef, { population: newPopulation });
});
});
});
发布于 2018-02-03 22:39:44
您不能将自己的“当前值”传递到事务中。但由于云函数仅在数据提交后触发,因此在事务中获取数据应该会在争用较少的文档中为您提供相同的值。
事实上:如果它没有给出相同的值,那是因为其他人已经再次更改了文档。在这种情况下,这就是为什么你不能传入自己的“这是当前值”的原因。
这听起来有点像XY problem。你能更新你的问题,告诉你想要完成的是什么,可能是哪些代码出了问题吗?
https://stackoverflow.com/questions/48602731
复制相似问题