I have an application in which I store the purchase record.
When a customer makes a purchase, an update is made in the document that represents the customer. The value of the purchase is added to the customer's total purchase and the product is added to an array that stores all the products that the client carries.
The error I have is that when there is a bad connection, sometimes it is registered as if the product had been bought twice. Then the total is added twice as much as the product and in the fix the duplicate product appears. I don't know how to fix it.
Here is the code in charge of updating in firestore
val data = hashMapOf(
"totalSale" to FieldValue.increment(purchaseValue), // -->
"soldProducts" to FieldValue.arrayUnion(product)) //this is the information that is repeated
FirebaseFirestore.getInstance().collection("client").document(id).update(data)