Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cost of updating multiple fields in a single call?

From Android example in documentation, it is clear that we can update multiple fields in a single update() call. I was wondering, does this call cost one write or n writes (n = the number of fields updated)?

// Assume the document contains:
// {
//   name: "Frank",
//   favorites: { food: "Pizza", color: "Blue", subject: "recess" }
//   age: 12
// }
//
// To update age and favorite color:
db.collection("users").document("frank")
        .update(
                "age", 13,
                "favorites.color", "Red"
        );
like image 425
Mangesh Avatar asked Dec 09 '25 16:12

Mangesh


2 Answers

What is the cost of updating multiple fields in a single call?

It will always cost a single write, no matter how many fields you update in a single update() call.

like image 133
Alex Mamo Avatar answered Dec 12 '25 04:12

Alex Mamo


Update should be counted in writes, ofcourse. I had started using Firestore again for my new project yesterday and did 2 write operations. I created 2 new documents with multiple fields and it costed me 2 writes. Then I updated 2 fields in a single document it costed me only 1.

So the answer is, it should cost you only 1 write.

The write count remains 1 irrespective of number of fields in a single document update() or write().

like image 37
Dharmaraj Avatar answered Dec 12 '25 04:12

Dharmaraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!