Firebase Tutorial on Firebase Write Data

in this chapter, we will show you how to save your data to firebase.

set

the set method will write or replace data on a specified path. let us create a reference to the player’s collection and set two players.

var playersref = firebase.database().ref("players/");

playersref.set ({
   john: {
      number: 1,
      age: 30
   },
	
   amanda: {
      number: 2,
      age: 20
   }
});

we will see the following result.

firebase write data set

update

we can update the firebase data in a similar fashion. notice how we are using the players/john path.

var johnref = firebase.database().ref("players/john");

johnref.update ({
   "number": 10
});

when we refresh our app, we can see that the firebase data is updating.

firebase write data update