要更新事务中的多个文档,请调用
t.update()
多次。
let promise = await admin.firestore().runTransaction(transaction => {
var post = transaction.get(docRef);
var anotherPost = transaction.get(anotherDocRef);
if (post.exists && anotherPost.exists) {
var newLikes = (post.data().likes || 0) + 1;
await transaction.update(docRef, { likes: newLikes });
newLikes = (anotherPost.data().likes || 0) + 1;
await transaction.update(anotherdocRef, { likes: newLikes });
}
})
看见
https://firebase.google.com/docs/firestore/manage-data/transactions#transactions