Realtime Database
Learn how to perform CRUD operations with Firebase Realtime Database
To read the data, follow the steps below:
- 2.Add a Code step
- 3.Type in the code below and Run Action:
const userId = firebase.auth().currentUser.uid;
return firebase
.database()
.ref('/users/' + userId)
.once('value')
.then(snapshot => snapshot.val());

Adding a Read Data step and checking the result
4. Check the Result tab - the data should sit in there.
To add a record:
- 1.
- 2.Select Code step and type in the code
- 3.Run Action:
const listRef = firebase.database().ref("list/");
listRef.set({
record1: {
field1: newValue1,
field2: newValue2,
},
});

Adding an Add Record step and checking the result
4. Check the Result tab to find a new record created.
Updates can be executed using 2 methods:
set()
and update()
. Let's check both of them.- 1.
- 2.Select Code step and type in the below code depending on the selected method:
set()
const listRef = firebase.database().ref("list/record");
listRef.set({
field1: newValue1,
field2: newValue2,
});
Note that
set()
can overwrite your data, while update()
just updates the required fieldsupdate()
const recordRef = firebase.database().ref("list/record");
recordRef.update({
field1: newValue1,
});

Adding an Update step and checking the result
3. Click Run Action
4.Check the Result section to for the outcome - the requested records should be updated with the new values.
- 2.Set Code step and insert the Code
- 3.Run Action
const recordRef = firebase.database().ref("list/record");
recordRef.remove();
4. Check the Result section to check that the record has been removed.
All the other operations with the Realtime Database data like Filter, Order can be done via the Firestore API. You can find an API reference here.
More useful articles on how to further manage your data:
Last modified 4mo ago