# Firestore

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

## Setup

[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.

Enter the following in the Terra Dashboard when adding the Firestore destination:

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

## Data Structure

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).


---

# 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://docs.tryterra.co/health-and-fitness-api/integration-setup/setting-up-data-destinations/firestore.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.
