0

when using firebase cloud function, let say if I want to insert some field into the firebase, I use ref.child().set(), but when I want to update the child, I can use both ref.child().update() and ref.child().set(). Is that a correct way to use ref.child().set() to update the field if the field is existed and to insert the field if the field is not exist? Because if I use ref.child().update(), I need to make sure the field data is inside the firebase. Thank you?

1 Answer 1

3

There is no difference in writing the initial value of a node and updating it. Both can be accomplished with either set() or update().

The difference between ref.set(...) and ref.update({...}) is that the first replaces everything that currently exists at ref, while the second updates only the keys/paths that are specified in the parameters.

I highly recommend checking out the documentation on updating nodes for an example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.