Firestore update

set vs update

The way I understood the difference:
  • set without merge will overwrite a document or create it if it doesn't exist yet
  • set with merge will update fields in the document or create it if it doesn't exists
  • update will update fields but will fail if the document doesn't exist
  • create will create the document but fail if the document already exists
There's also a difference in the kind of data you provide to set and update.
For set you always have to provide document-shaped data:
1
set(
2
{a: {b: {c: true}}},
3
{merge: true}
4
)
Copied!
With update you can also use field paths for updating nested values:
1
update({
2
'a.b.c': true
3
})
Copied!
​
Last modified 2yr ago
Copy link