# Update a document

This action allows you to edit/update document in a Firestore collection.

You still don't need to have the collection or "table schema" pre-determined. You can create any fields you'd like during document updates.

***

## <mark style="color:blue;">Inputs and Settings</mark>

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2Fe0jGXwO697dfGz0f7QrW%2Fimage.png?alt=media&#x26;token=76416478-79aa-40af-a5af-49a36ca493fc" alt=""><figcaption></figcaption></figure></div>

### Document ID

The ID of the document you want to update.

### Collection

The name or ID of the collection the document you want to update is stored in.

### Trigger ID (optional)

This will link the action with a [Action Listener](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/plugin-elements/firebase-action-listener) of the same ID.&#x20;

If left blank, all listeners on the page with blank ID's will be triggered at the same time, so we suggest to always define a Trigger ID.

When the function finishes running, it will trigger the [Document Updated](https://estare.gitbook.io/firebase-auth-firestore-storage-plugin/plugin-elements/firebase-action-listener#document-updated) event, storing the [Updated Document ID](https://estare.gitbook.io/firebase-auth-firestore-storage-plugin/plugin-elements/firebase-action-listener#updated-document-id) on the listener's state.

### Fields

The same way as on the [Create New Document action](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/plugin-front-end-actions/firestore/create-a-new-document) you must inform which fields you want to update, in JSON format. This input allows you to set as many fields as you want.

For each field you must specify the "key" and the "value" that will be stored on it. For instance, you might want to invert the value of the "done" field in a task on our [task manager sample app](https://estare-plugin-firestore.bubbleapps.io/version-test), when the check icon is clicked. You'd need to define the "key" = "done" and the "value" = "true" or "false".

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2FQcstZE8ec6CPNg60yJzD%2Fimage.png?alt=media&#x26;token=77c84d00-e844-4e3c-91a5-f6da1606fce5" alt=""><figcaption><p>The "done" field is set to the opposite of the current tasks "done" value. If "true", it'll be updated to "false", and <em>vice versa</em></p></figcaption></figure></div>

### Field Types

For each key/value pair you define and provide a value on the Fields list, you must provide the same key, but with the type of the value, on the Field Types input. That allows the plugin to turn the texts being fed into the plugin into corresponding values on the JSON structure sent to Firestore.

If the number of Fields and Field Types don't match, the action will result in an error.

<div align="left"><figure><img src="https://284736847-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiWu3FezEjWxrPbkf8zIP%2Fuploads%2FqjLv504UI1CTGKNprc1Z%2Fimage.png?alt=media&#x26;token=4cc722ce-2b3e-4a45-9198-efaa0630b01a" alt=""><figcaption></figcaption></figure></div>

See the [field types table](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/plugin-front-end-actions/field-types-table) to see which types are currently supported by the plugin and how to define them.

***

## <mark style="color:blue;">Triggered events</mark>

Those events are triggered by an [Action Listener](https://estare.gitbook.io/firebase-auth-firestore-and-storage-plugin/plugin-elements/firebase-action-listener) with the same ID as the [Trigger ID](#trigger-id-optional) provided on the action.

* Document Updated (if the action was successful)
* Error in Action (if an error occurs)

***

## <mark style="color:blue;">Stored values on the listener</mark>

### Updated Document ID

The ID of the document updated by the action.

### Error Message

If an error occurs, you can check its details on this state on the action listener.
