# Save data in DB

![](https://476758574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVctm8W2AAd8SbIYUaj27%2Fuploads%2FydWKRq1uadcSMFbEWzzj%2FScreen%20Shot%202022-07-28%20at%2015.22.10.png?alt=media\&token=778874de-eaed-48b1-bd9c-0a894aa1ce8e)

{% tabs %}
{% tab title="Entry Vars" %}
**Update DB caché:** Activating the switch allows the function to update the cache of the query to the database, to show updated data.

**Updates to make to the DB:** Allows access to the database structure to add fields and create or update a new record

**Step by Step :**

<figure><img src="https://476758574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVctm8W2AAd8SbIYUaj27%2Fuploads%2Fgyutd0SOKWt3N0RtSAdN%2FSave%20data%20in%20DB.gif?alt=media&#x26;token=b5771bdf-9e64-4e16-bc82-37bf30101081" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Callbacks & OutVars" %}

* **Error saving data:** Triggered when an error occurs when saving or updating a record in the database collection

&#x20; OutVars&#x20;

`Null`

* **End:** It is activated once the function has died, regardless of whether the function's task succeeded or failed.

&#x20;OutVars&#x20;

`Null`

* **Data saved:** Activated when the function successfully saved or updated a data or record

&#x20;OutVars&#x20;

`Null`
{% endtab %}

{% tab title="Features" %}
Esta funcioón permite trabajar de dos formas:

1. **Crear registro:** Para poder crear un nuevo registro, es necesario que el ID del registro no exista con anterioridad en la colección de datos.
2. **Actualizar registros:** Para poder actualizar un registro, es necesario que el registro exista y se debe colocar el ID del registro en el campo identifier del path. Puedes agregar datos en campos vacios o actualizar campos con información actualizada.

Cuando se agrega un nuevo registro, pero en el campo identifier no se coloca ningún ID personalizado o automatico, por defecto, la funcioón agregará un ID único, aleatorio e irrepetible.

No se pueden agregar nuevos registros si este no cuenta con informacioón para llenar al menos un campo del registro

Para anidar colecciones a un registro es necesario siempre saber el ID delnregistro en que deseamos agregar la nueva coleccón
{% endtab %}

{% tab title="examples" %}
![](https://476758574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVctm8W2AAd8SbIYUaj27%2Fuploads%2FQGj9zvIW0YaecsjIgGuy%2FWhatsApp%20Image%202022-07-28%20at%203.50.42%20PM.jpeg?alt=media\&token=9686e866-63fb-4e5d-860f-58f0297535ba)
{% endtab %}
{% endtabs %}
