# MongoDB

> A managed MongoDB database. One command, one connection string.

```bash
npx extraorbital add mongodb
```

```txt
✓ Provisioned mongo/default (database cosmic-otter-default)
✓ Wrote 1 variable to .env — MONGODB_URI
```

Both `mongodb` and `mongo` work; the resource is addressed `mongo/default`. A project
that mentions `MONGODB_URI` anywhere gets this from
[`extraorbital provision`](/docs/quickstart#how-autopilot-decides) without naming it.

## What it writes

| Variable | Example |
| --- | --- |
| `MONGODB_URI` | `mongodb+srv://cosmic-otter-default:…@mongo.extraorbital.dev/cosmic-otter-default` |

A dedicated MongoDB 7 database with a user scoped to it. The connection string
carries the credentials, the database name and TLS, so one variable is all your code
needs.

## Options

```bash
npx extraorbital add mongodb [--slug <name>] [--region <region>]
```

| Flag | Default | Description |
| --- | --- | --- |
| `--slug` | `default` | A second, fully separate database in the same project |
| `--region` | `us-east-1` | One of `us-east-1`, `eu-central-1`, `ap-southeast-1` |

Options apply at creation. Re-running `add` with different options returns the
existing database unchanged.

## Prototype allowance

**512 MB of storage on shared RAM and vCPU** on the Prototype plan, counted
across your whole account and shared by up to five databases. Past it a database
starts at $8.00/mo and scales with its size — our own cost, with nothing added —
on [a paid plan](/pricing).

## Use it

```ts title="db.ts"
import { MongoClient } from "mongodb";

const client = new MongoClient(process.env.MONGODB_URI!);

const events = client.db().collection("events");
await events.insertOne({ type: "boot", at: new Date() });
```

`client.db()` with no argument uses the database from the connection string, which is
the one your credentials are scoped to.

## Next

- [Quickstart](/docs/quickstart) — slugs, idempotency and sharing
- [Pricing](/pricing) — plans, allowances and rates

---

More for agents: [Docs index](https://extraorbital.dev/sitemap.md) · [llms.txt](https://extraorbital.dev/llms.txt) · [agents.md](https://extraorbital.dev/agents.md)
