2

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

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121

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,880
  • 12
  • 34
  • 44
Belbahar Raouf
  • 760
  • 1
  • 4
  • 17