- Firebase Tutorial
- Firebase - Home
- Firebase - Overview
- Firebase - Environment Setup
- Firebase - Data
- Firebase - Arrays
- Firebase - Write Data
- Firebase - Write List Data
- Firebase - Write Transactional Data
- Firebase - Read Data
- Firebase - Event Types
- Firebase - Detaching Callbacks
- Firebase - Queries
- Firebase - Filtering Data
- Firebase - Best Practices
- Firebase - Email Authentication
- Firebase - Google Authentication
- Firebase - Facebook Authentication
- Firebase - Twitter Authentication
- Firebase - Github Authentication
- Anonymous Authentication
- Firebase - Offline Capabilities
- Firebase - Security
- Firebase - Deploying
- Firebase Useful Resources
- Firebase - Quick Guide
- Firebase - Useful Resources
- Firebase - Discussion
Firebase - Write Transactional Data
Transactional data is used when you need to return some data from the database then make some calculation with it and store it back.
Let us 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 the age from the collection and then we can use the 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.
Advertisements