2

Can someone please help me elaborate difference between setValue() and push() methods in Firebase? Thanks in Advance.

Renaud Tarnec
  • 66,768
  • 8
  • 72
  • 104

1 Answers1

9

SetValue() is to write or replace data in a defined path. Example : I want to set the username for a given user :

Firebase.getInstance().getReference().child("user").child("username").setValue("Jhon Doe");

SetValue() can also be used to delete data in a defined path by calling it without parameters:

Firebase.getInstance().getReference().child("user").child("username").setValue();

Push(), is used to add a new node. So, every time this method is called, firebase will automatically generate a new unique ID. Calling Push() without parameters won't actually create any data in the database but only generate the unique ID (on the client side).

André Kool
  • 4,668
  • 12
  • 33
  • 43
Belbahar Raouf
  • 740
  • 1
  • 4
  • 17