我有这段代码,我尝试使用 bacth 在我的集合中创建新字段,我想用这个条件 ((index + 1) % 500 === 0) 验证以使用提交,有什么问题吗?
const myFunction = async () => {
try {
let batch = db.batch()
const batchCommits = []
await schoolList.forEach(async (school, index) => {
await ref
.doc(school.id)
.collection('mycollection')
.where('visual', '==', 'none')
.get()
.then(async (querySnapshot) => {
if (querySnapshot.empty) {
const curses = await ref
.doc(school.id)
.collection('curses')
.doc()
batch.set(curses, common)
if ((index + 1) % 500 === 0) {
batchCommits.push(batch.commit())
batch = db.batch()
}
}
})
})
batchCommits.push(batch.commit())
return Promise.all(batchCommits)
}
}
我收到此错误:错误:无法修改已提交的 WriteBatch。
倚天杖
相关分类