Issue
I have a "Users" data structure like this, I want to increment the value of ttl_user
by 1 when a user is signed up. And decrement it by 1 when a user has deleted their account.
How can I update the value? Thanks.
Solution
In your particular case, it would be as simple as:
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
DatabaseReference userRef = db.child("User");
userRef.child("ttl_user").setValue(ServerValue.increment(1));
And to decrement, simply pass a negative value -1
.
Answered By - Alex Mamo
Answer Checked By - Pedro (JavaFixing Volunteer)