I want to update one field and, in some case, another field of the same document in a batch:
db.runBatch { batch ->
val myRef = db.document("path/to/document")
batch.update(myRef, "foo", "bar")
if(someCondition) {
batch.update(myRef, "baz", "bar")
}
}
Is this billed as a single write or as two writes in case someCondition is true?
As an alternative I could do something like this:
db.runBatch { batch ->
val myRef = db.document("path/to/document")
if(someCondition) {
batch.update(myRef, "foo", "bar", "baz", "bar")
} else {
batch.update(myRef, "foo", "bar")
}
}
But that leads to duplicating code and becomes very messy in case of updating more fields