【发布时间】:2018-08-24 19:05:51
【问题描述】:
我在云函数上部署此代码,得到无法修改已提交的 WriteBatch,我在获取每个集合后尝试提交,但这不是正确的方法并且不一致,尝试几个小时后无法发现错误。代码在冷启动后第一次运行,这个帖子有同样的问题Batch write to firebase cloud firestore,在哪里创建
每组写入一个新批次。 在这段代码中。
var batch = db.batch();
db.collection("myposts")
.doc(post_id)
.collection("fun")
.get()
.then(snapshot => {
return snapshot.forEach(doc => {
batch.delete(doc.ref);
});
})
.then(
db
.collection("relations_new")
.where("uid", "==", uid)
.get()
.then(snapshot => {
return snapshot.forEach(doc => {
batch.delete(doc.ref);
});
})
)
.then(
db
.collection("relation")
.where("uid", "==", uid)
.get()
.then(snapshot => {
return snapshot.forEach(doc => {
batch.delete(doc.ref);
});
})
.catch(err => {
console.log(err);
})
)
.then(
db
.collection("posts")
.doc(post_id)
.get()
.then(snap => {
return batch.delete(snap.ref);
})
.then(batch.commit())
)
.catch(err => {
console.log(err);
});`
【问题讨论】:
标签: node.js firebase transactions google-cloud-firestore google-cloud-functions