# Firestore update

<https://firebase.google.com/docs/firestore/manage-data/add-data#update-data>

## **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:
>
> ```javascript
> set(
>   {a: {b: {c: true}}},
>   {merge: true}
> )
> ```
>
> With update you can also use field paths for updating nested values:
>
> ```javascript
> update({
>   'a.b.c': true
> })
> ```

from [Difference between set with {merge: true} and update](https://stackoverflow.com/questions/46597327/difference-between-set-with-merge-true-and-update)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://textav.gitbook.io/firebase-react-notes/firestore/firestore-update.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
