> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/destinations/firestore.md).

# Firestore

Store full Terra payloads as documents in your Google Cloud Firestore database, organised by event and data type.

Terra can store health data directly in your [Google Cloud Firestore](https://cloud.google.com/firestore) database, with full payloads stored inline as documents.

## Before you begin

* A Google Cloud project with a Firestore database.

## Create a service account

[Create a service account](https://developers.google.com/workspace/guides/create-credentials#service-account) with Firestore read/write access to your project. Download the JSON credentials file.

## Add the destination in Terra

On the [Connections page](https://dashboard.tryterra.co/dashboard/connections) in your Terra dashboard, click **Add New**, add the Firestore destination, and enter:

* **GCP Project ID**
* **Service account credentials** (JSON file upload)

## What Terra writes

Terra organises documents in a hierarchical collection structure under a `terra/2022-03-16` base path.

### Collections

| Collection path                 | Contents                                 | Document name                 |
| ------------------------------- | ---------------------------------------- | ----------------------------- |
| `terra/2022-03-16/user_events`  | Auth events (auth success, deauth, etc.) | `{user_id}-{timestamp}.json`  |
| `terra/2022-03-16/activity`     | Activity data                            | `{user_id}-{start_time}.json` |
| `terra/2022-03-16/body`         | Body metrics                             | `{user_id}-{start_time}.json` |
| `terra/2022-03-16/daily`        | Daily summary data                       | `{user_id}-{start_time}.json` |
| `terra/2022-03-16/sleep`        | Sleep data                               | `{user_id}-{start_time}.json` |
| `terra/2022-03-16/nutrition`    | Nutrition data                           | `{user_id}-{start_time}.json` |
| `terra/2022-03-16/menstruation` | Menstruation data                        | `{user_id}-{start_time}.json` |

### Document format

All documents contain the full data payload inline. There are no external URLs to download. Data event documents include the `user` object alongside the data fields.

Documents are overwritten if a document with the same name already exists (last write wins).

## Next steps

* [User authentication](https://docs.tryterra.co/unified-api/authentication-flow.md): link a user's wearable so events start flowing.
* [Event delivery](https://docs.tryterra.co/destinations/events.md): see what each delivery status means and how retries work.
* [Health data events](https://docs.tryterra.co/unified-api/receiving-data-updates.md): process the data Terra delivers.
