I\'m trying to create a WriteBatch
to keep control of one of my dynamic references in my database. My app have a simple User-Follow-Post-Feed
model
Finally the problem was caused because I was trying to realize this batch operations inside a transaction, which also acts like a batch in the end. That's why even I was generating batches for each 400 references, these instances were created inside a transaction and it counts like a single big transaction which surpass the 500 limit.
I made a few changes and implemented on a repository on my GitHub.
//Generate the right amount of batches
const batches = _.chunk(updateReferences, MAX_BATCH_SIZE)
.map(dataRefs => {
const writeBatch = firestoreInstance.batch();
dataRefs.forEach(ref => {
writeBatch.update(ref, 'author', newAuthor);
});
return writeBatch.commit();
});
It is writed on typescript, but you will understand it for sure: https://github.com/FrangSierra/firestore-cloud-functions-typescript/blob/master/functions/src/atomic-operations/index.ts