Conchi Bermejo
Conchi Bermejo

Reputation: 353

Does a Firestore batch.set() to a same document counts as one document write?

If I do this in my code

 function setShards(batch, docRef, numShards) {
    batch.set(docRef, { numShards } , { merge: true });
 }

 const batch = firestore.batch();

 batch.set(docRef, {data});
 
 setShards(docRef, 10);

 batch.commit();

as you can see I am making a batch.set to the same document before doing the .commit(). So, will this count as one document write or as two document writes?

Thank you.

Upvotes: 2

Views: 1656

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317828

batch.set() does not directly cost any document writes. It is just queuing up a change locally before being sent to Firestore. No billing occurs until you call batch.commit() successfully. At that point, you will be charged as many document writes as are changes in the entire batch. So, if you only write one document in the batch, you will be charged on document write.

Upvotes: 7

Related Questions