第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用批處理創(chuàng)建多個文檔?

如何使用批處理創(chuàng)建多個文檔?

慕蓋茨4494581 2023-07-06 19:46:22
我有這段代碼,我嘗試使用 bacth 在我的集合中創(chuàng)建新字段,我想用這個條件 ((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。
查看完整描述

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()

    }


查看完整回答
反對 回復(fù) 2023-07-06
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號