Templates

MongoDB

Deploy MongoDB 7 with persistent storage — document database with auto-generated credentials

Ink deploys MongoDB 7 as a container service with a persistent volume. Your agent provisions the database using a template — credentials are auto-generated and returned immediately.

Deploying

Your agent uses the template_deploy MCP tool:

Tool Call
(
  : "mongodb",
  : "my-db"
)
{
  "services": [object Object],
  "outputs": [object Object]
}

Or via the CLI:

ink template deploy mongodb --name my-db

Auto-generated credentials

VariableValue
MONGO_INITDB_ROOT_USERNAMEadmin
MONGO_INITDB_ROOT_PASSWORDAuto-generated at deploy time
DATABASE_URLFull connection string with generated credentials

Passwords are randomly generated. The agent receives them as outputs — no manual password management required.

Persistent storage

A persistent volume is attached at /data/db (1 Gi default). Data survives container restarts and redeployments.

Connecting

After deployment, template_deploy returns a DATABASE_URL in the format:

mongodb://user:pass@hostname:27017/dbname?authSource=admin

The internal URL (my-db:27017) is used for service-to-service communication within the same project. Any sibling service can connect by hostname — no external networking required.

Client libraries

Node.js

npm install mongodb
import { MongoClient } from 'mongodb';

const client = new MongoClient(process.env.DATABASE_URL);
await client.connect();

const db = client.db();
const users = await db.collection('users').find().toArray();

Python

pip install pymongo
import os
from pymongo import MongoClient

client = MongoClient(os.environ["DATABASE_URL"])
db = client.get_default_database()
users = list(db.users.find())

Specs

PropertyValue
EngineMongoDB 7
Imagemongo:7
Port27017
Volume/data/db
Default Memory512Mi
Default vCPU0.5

On this page