Can someone please help me elaborate difference between setValue() and push() methods in Firebase? Thanks in Advance.
Asked
Active
Viewed 2,762 times
2
-
1@RaajNadar Nope thats not a duplicate. This question is about the difference between push() and set() and you duplicate is about update() and set(). – André Kool Apr 16 '18 at 14:03
-
1https://firebase.google.com/docs/database/admin/save-data read this page – Rajendran Nadar Apr 16 '18 at 14:09
-
Why did they mark it as duplicate?! It's totally not! I gave you +1 – SHAI Nov 06 '18 at 21:37
1 Answers
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
-
-
-
If this helped you, please mark as answered so other people can find it easily. Thank you. – Belbahar Raouf Apr 17 '18 at 12:05