Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrease a value using FieldValue in Firestore (SWIFT)?

Reading a blog post and the docs, I found that we can increment a value using FieldValue but I cound't find a decrement function.

document("fitness_teams/Team_1").
  updateData(["step_counter" : FieldValue.decrement(500)]) //Does not exist

To decrement a value we still need to use transactions?

like image 345
Dave Avatar asked Oct 19 '25 23:10

Dave


1 Answers

There is no need for a decrement function, simply pass a negative value to the actual increment() function:

document("fitness_teams/Team_1").
  updateData(["step_counter" : FieldValue.increment(-500)])

And the value of your step_counter field will be decremented by 500.

like image 176
Alex Mamo Avatar answered Oct 21 '25 14:10

Alex Mamo



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!