Let's say we have one player inside our player list.
We want to retrieve property, add one year of age and return it back to Firebase.The amandaRef is retrieving age from the collection and then we can use transaction method. We will get the current age, add one year and update the collection.
var ref = new Firebase('https://tutorialsfirebase.firebaseio.com'); var amandaAgeRef = ref.child("players").child("-KGb1Ls-gEErWbAMMnZC").child('age'); amandaAgeRef.transaction(function(currentAge) { return currentAge + 1; });If we run this code, we can see that the age value is updated to 21.

No comments:
Post a Comment