1 回答

TA貢獻(xiàn)1828條經(jīng)驗 獲得超3個贊
我的理解是,您可以使用 for of 循環(huán)即 for(const school of Schools) 來處理結(jié)果。這很粗糙,但也許像下面這樣?不太確定是否將批次合并到一個承諾中。all
如果您已經(jīng)解決了這個問題,請發(fā)布您的解決方案。
let batch = db.batch()
for( const school of schoolList) {
const myCollectionDoc = await ref.collection('mycollection')
.doc(school.id)
.get()
if(myCollectionDoc.empty) {
const curses = await ref.doc(school.id).collection('curses').doc()
batch.set(curses, common)
}
if (batch._writes.length === 500) {
await batch.commit()
batch = db.batch()
}
}
if (batch._writes.length != 0) {
await batch.commit()
}
添加回答
舉報