Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between setValue() and updateChildren()?

I have done research about setValue() and updateChildren(). I have tested both of them to add and update data from firebase database. From what I have learnt that both of them did the same exact thing and did some research about them.

From what I have learnt. The setValue() is used with a class object while updateChildren() is used with a Map or HashMap. Correct me if I'm wrong.

My question is as stated above, what is the difference between setValue() and updateChildren()?

like image 357
UmarZaii Avatar asked Jan 03 '23 20:01

UmarZaii


1 Answers

'setValue' method is totally replacing the document (specified reference) with new data.

'updateChildren' method is just updating particular fields or add such fields if they did not exist before.

You often can get the same result using those methods, but actually they are different.

like image 198
Artem Arkhipov Avatar answered Jan 13 '23 13:01

Artem Arkhipov