I have been having an issue with Firestore batch commits trying to update a collection of documents regularly, or when trying to write a large set of data. Firestore seems to just freeze and won't send a response. In both cases, recommendations for maximum batch size (500) and document size is respected. Using cron-jobs, for example, the commits run successfully for some time before stopping altogether without any error trace.
For example, the code below gets executed for 6 times in a row before starting to misbehave.
public updateCoins = async () =>{
const markets = await this.getMarkets('usd')
const maxCount = Math.round(markets.length/this.FB_BATCH_SIZE) + 1
for(let i=0; i< maxCount; i++){
const marketBatch = markets.slice(i*this.FB_BATCH_SIZE, (i+1)*this.FB_BATCH_SIZE > markets.length ? markets.length : (i+1)*this.FB_BATCH_SIZE)
const batchCoins = this.fbService.db.batch()
marketBatch.map((entry)=>{
const coin = this.mapCoin(entry)
if(coin){
const coinRef = this.coinsCol.doc(coin.id);
batchCoins.set(coinRef,coin,{merge:true})
}
})
await batchCoins.commit()
.then(()=>{
console.log('Commited coins batch update')
}).catch((_e)=>{
console.log('Exception saving coins',_e)
})
}
}