# Database

{% hint style="info" %}
Supported providers:

* [Firestore](#firestore)
* [MongoDB](#mongodb)
  {% endhint %}

### Firestore 🔥

1. If you haven't already create a firebase project: <https://firebase.google.com/docs/firestore/quickstart>.
2. Add Firestore database, to your project in Firebase
3. In Firebase side panel, navigate to: `Project Overview -> Project Settings -> Service Accounts -> Generate new private key` to generate service account json file, which contains private key. You can also visit this URL: `https://console.firebase.google.com/u/0/project/{project-id}/settings/serviceaccounts/adminsdk` but replace the `{project-id}` with your project.

   <figure><img src="/files/ixHGE3DAgw22fImBmvJb" alt="" width="375"><figcaption></figcaption></figure>
4. Set following `.env` variables:\
   `AUTH_FIREBASE_PROJECT_ID` - id of your firebase project\
   `AUTH_FIREBASE_CLIENT_EMAIL` - service account email (get it from step 3 json file)\
   `AUTH_FIREBASE_PRIVATE_KEY` - private key (get it from step 3 json file)
5. Now your Firestore is setup :)

### MongoDB 🧩

1. Create MongoDB account and cluster if you haven't already: <https://account.mongodb.com/account/register>
2. Now we need to create an extra user which will be only used by our app. It needs to have read/write access. In side panel, go to `Security -> Database Access -> Add new Database user`&#x20;

   <figure><img src="/files/ruWxLXma16ejWuYaUv2K" alt="" width="375"><figcaption></figcaption></figure>
3. Now we need to get "connection string" URI. In side panel, go to `Deployment -> Database -> Connect`. After modal opens, select `Drivers` and at the bottom you will see connection string looking like `mongodb+srv://<db_username>:<db_password>@...`&#x20;

   <figure><img src="/files/vM2wbxGx9m7RHSm7Yl42" alt="" width="375"><figcaption></figcaption></figure>
4. Set following `.env` variables:\
   `MONGO_DB_URI` - connection string from step 3\
   **Note**: Make sure that after first `/` in connection string, you write the DB name which you want to use (otherwise by default it's `test`). Example of connection string: `mongodb+srv://{username}:{password}.../dbName`
5. Now your MongoDB is setup :)

### Configuration

Database adapter is controlled through the `appConfig.ts`file.

```json
database: {
  provider: DatabaseType.FIRESTORE // or DatabaseType.MONGODB
}
```

Each adapter has it's own set of required environment variables, together with it's own implementation of common functions to interact with the database.

Adapters don't implement actual business logic. Business logic is handled in the `database/index.ts`file together with "collection names".

Collection names are names of tables/collections in the database.


---

# 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://accelerator.gitbook.io/docs/setup/database.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.
