I have an existing document with count value as 1. When i use FieldValue.increment(1) using setData (which should overwrite with new incremented value), it does not increment the value, but using the same with updateData, increments the value to 2.
Why is that? What is the difference between setData and updateData in this case, especially when I am updating with same number of attributes?
setandupdateis that the first assumes there's nothing at the given path, so it will not throw an error when there is no pre-existing document, whereasupdatewill. Noticed the previous answers did not mention anything about that, nor about the reason why your code returns different values for each action.