# Host a MongoDB database

A MongoDB measured on Estiba for a few small apps costs about $1.95 a month. Your AI agent creates it with a password and its files kept.

## Put it online

1. [Sign up](https://app.estiba.cloud) and [connect your agent](https://estiba.cloud/docs/connect-your-agent) to Estiba, once.
2. Ask it: "create a MongoDB database on Estiba".
3. Your agent creates it from the official image, with a version that only changes when you say so. It keeps the database's files in a volume, at `/data/db`, so they last when it restarts or moves. The admin user's password goes in as a secret: stored encrypted and never shown again, not even to the agent, so keep the one it gives you.
4. It gives the database a port and tells you its address, such as `ports.estiba.cloud:21450`.
5. [Add credit](https://estiba.cloud/docs/credit-and-prices), from $5. The database starts once there is credit.

It runs a single MongoDB, not a replica set: enough for most apps and bots.

## Connect to it

Use a connection string with MongoDB Compass, mongosh or your app's driver (Mongoose, the Node.js or Python driver):

```
mongodb://admin:PASSWORD@ports.estiba.cloud:21450/?authSource=admin
```

Your apps on Estiba connect to the same address, wherever each one runs; your agent puts the string in the app as a secret. Ask it for a user for each app, with access to its own database only.

The address is open to the internet, like any database on a port: the password is what keeps others out, so use a long one. The connection is not encrypted unless the database is set up with TLS: for data that matters from outside Estiba, ask your agent to turn it on.

## What it costs

You pay for what it uses, measured every second: $4 per GB of memory and $8 per vCPU busy, a month, and $0.10 per GB its files take, taxes included. Your agent keeps it always on, so it never sleeps and your apps always find it.

MongoDB keeps a cache in memory even when it holds little. For example, a MongoDB measured on Estiba for a few small apps holds about 440 MB of memory, keeps 2 % of a vCPU busy and its files take 360 MB: 0.44 × $4 + 0.02 × $8 + 0.36 × $0.10 = **about $1.95 a month**. Your agent can make that cache smaller if the data is small. The dashboard shows what yours really uses and costs each day.

## Back it up

Ask your agent for a dump: it runs `mongodump` against the address and saves it on your computer. Don't copy the database's files from the volume while it runs; a dump is the safe copy, best made while your apps are quiet.

## If a server goes down

The database keeps its files in its volume, so if the machine it runs on goes down, it waits for it to come back instead of starting somewhere else without them. When Estiba moves it to another machine, its files go with it and the address stays the same; the move restarts it for a few seconds and apps reconnect.
