Skip to content

MongoDB

Curated name mongodb. Adds a MongoDB 8 service to the workbench in compose mode, with seeded dev credentials and a readiness healthcheck.

A document database for local development - a real MongoDB your app runs against, with a root user seeded for you. Use it when your stack stores documents/JSON rather than relational rows.

At init, or to an existing workbench:

Terminal window
monoceros init acme --with-services=mongodb
monoceros add-service acme mongodb

Need a second database? Add it again under a different name with --as - each instance gets its own host, data dir, and connection env:

Terminal window
monoceros add-service acme mongodb --as=events
Terminal window
monoceros remove-service acme mongodb

Or delete the service’s block from acme.yml by hand and re-run monoceros apply acme - the yml is the source of truth. (Its data volume monoceros-acme-data-mongodb is removed with the workbench on monoceros remove, which backs it up first.)

acme.yml
services:
- name: mongodb # host name in the container + data dir name
image: mongo:8
port: 27017 # in-container port (feeds `monoceros tunnel`)
env:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} # values live in acme.env
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
volumes:
- data:/data/db # the service's own Docker volume
restart: unless-stopped
healthcheck: # workspace waits for service_healthy
test: [CMD, mongosh, --quiet, --eval, 'db.adminCommand({ ping: 1 }).ok']
interval: 10s
timeout: 5s
retries: 5
connectionEnv: # → the workspace env vars below
URL: mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@${host}:${port}/${MONGO_INITDB_DATABASE}?authSource=admin
HOST: ${host}
PORT: ${port}
USER: ${MONGO_INITDB_ROOT_USERNAME}
PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
DB: ${MONGO_INITDB_DATABASE}

The credentials are ${VAR} references; the real values live in acme.env (dev default monoceros for user, password, and database), so the yml stays shareable without baking credentials in (see Workbench configuration).

Monoceros injects a connection env into the workspace container, prefixed with the service name:

VariableValue (defaults)
MONGODB_URLmongodb://monoceros:monoceros@mongodb:27017/monoceros?authSource=admin
MONGODB_HOSTmongodb
MONGODB_PORT27017
MONGODB_USERmonoceros
MONGODB_PASSWORDmonoceros
MONGODB_DBmonoceros

The URL carries ?authSource=admin because the seeded user is the root user (authenticated against the admin database). The prefix is the service name, uppercased, so a second instance added with --as=events gets EVENTS_URL, … and never collides.