# 3. Connect your Database

Cosmocloud champions your data sovereignty with the innovative **BYOD model - Bring Your Own Database.**

Take complete control of your data, knowing that we prioritise your ownership above all. At Cosmocloud, your privacy is paramount; we never own your data. Experience true autonomy and peace of mind, as Cosmocloud empowers you to steer your projects with full confidence and security.

{% hint style="info" %}
Cosmocloud can spin up dedicated databases for you in Pro projects, on demand. To get Cosmocloud to spin up dedicated databases for Pro projects, reach out to [Cosmocloud Support](mailto:support@cosmocloud.io).
{% endhint %}

{% embed url="<https://www.youtube.com/watch?v=ikve8ADVVFY>" fullWidth="false" %}
Connecting your Database
{% endembed %}

## Linking your Database

Start by linking your own MongoDB Database with Cosmocloud's project. On Free Tier, Cosmocloud only supports MongoDB Atlas's Data APIs to connect to your database. As you upgrade to Pro, Cosmocloud uses native connection pools (using MongoDB SDK) to connect.

{% hint style="warning" %}
It is not advised to use a Free Tier Project for Production use cases. Checkout [how to upgrade to a Pro Project](https://docs.cosmocloud.io/getting-started/broken-reference)<mark style="color:blue;">.</mark>
{% endhint %}

Currently, Cosmocloud only supports MongoDB, but integration with more databases is in works behind the scenes and we’ll bring them to you soon!

### Steps to connect you cluster

You can start free by [spinning up an M0 cluster](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/) on your own [MongoDB Atlas account](https://cloud.mongodb.com) and then connecting the same with Cosmocloud with below steps!

Once your cluster is ready, follow these steps -

1. Head over to the **Secrets** tab in your project to start creating a secret
2. When creating your secret, choose the environment required. On the Free Tier, the only env available is Development.

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FxHbLV5fIiv6fDZOvQo6I%2FScreenshot%202024-04-22%20at%2011.50.52%E2%80%AFPM.png?alt=media&#x26;token=81d8a252-0789-466a-9715-576860db50f7" alt=""><figcaption></figcaption></figure>

Next, you will be prompted to input your MongoDB cluster details. Then, Head over to[ MongoDB Atlas](https://cloud.mongodb.com/), create a new Database Cluster, or use an existing one.

3. Create an **API key** for Cosmocloud to connect to MongoDB Atlas.
   1. Open your MongoDB Atlas account.
   2. Click on **Access Manager** on the top of MongoDB Atlas page and select **Project Access**.
   3. Click on **Create API Ke**y on the left side.
   4. **\[Important]** Name your key `cosmocloud-apikey` and give it **Project Owner** role.
   5. On the next step, copy your **Private and Public keys** and store them securely, to be used in Step 4.
4. When creating a **Database** type Secret, Cosmocloud will ask you for these details -
   1. **Database name:** The name of the logical DB where your data would be stored.
   2. **MongoDB Atlas Public Key:** The public key you copied above.
   3. **MongoDB Atlas Private Key:** The private key you copied above.
   4. **Project ID:** Your MongoDB Atlas Project's ID. You can find this on your MongoDB Atlas project's settings page.
   5. **Cluster name:** The name of the Atlas Cluster you created (case sensitive, for eg. Cluster0)

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FsycTMNJAzKZqHUakAkVL%2FScreenshot%202024-04-22%20at%2011.50.27%E2%80%AFPM.png?alt=media&#x26;token=51b58917-fbef-4198-b812-c10cce09ac88" alt=""><figcaption></figcaption></figure>

After clicking on Create, it will take **30-45 seconds (on Free Tier)** to establish a test connection with MongoDB, and a success message will be displayed. In case there’s an error in filling up the secrets, you will be notified about the same

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FACZzoqX7hgaNFpy9romv%2FScreenshot%202024-04-22%20at%2011.54.14%E2%80%AFPM.png?alt=media&#x26;token=c2c0d446-4842-497b-9fab-3909f0443407" alt=""><figcaption></figcaption></figure>

You now have successfully connected your 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://docs.cosmocloud.io/getting-started/3.-connect-your-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.
