MongoDB is a source-available, cross-platform, document-oriented database program. Classified as a NoSQL database product, MongoDB uses JSON-like documents with optional schemas.
This add-on integrates MongoDB and Mongo Express into your DDEV project.
It's based on MongoDB from Docker Hub, DDEV custom compose files and API Platform tutorial.
ddev add-on get ddev/ddev-mongo
ddev restartAfter installation, make sure to commit the .ddev directory to version control.
Warning
MongoDB 8 doesn't start on Linux kernel 6.19 through 7.0.13 (for example, Ubuntu 26.04), see #40.
Containers use the kernel of the Docker host, check it with docker info --format '{{.KernelVersion}}'.
If it's in that range, use MongoDB 7.0 until you can upgrade to kernel 7.0.14 or later:
ddev dotenv set .ddev/.env.mongo --mongo-docker-image=mongo:7.0
ddev add-on get ddev/ddev-mongo
ddev restartBy default, the database with the name db is created. You can connect to it using this connection string:
mongodb://db:db@mongo:27017/db?authSource=admin
You can change the default database name, username, and password using env variables:
ddev dotenv set .ddev/.env.mongo \
--mongo-initdb-root-username=db \
--mongo-initdb-root-password=db \
--mongo-initdb-database=dbIf you want to disable authentication:
ddev dotenv set .ddev/.env.mongo \
--mongo-initdb-root-username="" \
--mongo-initdb-root-password="" \
--me-config-mongodb-url=mongodb://mongo:27017-
Your project will likely require the Doctrine MongoDB ODM bundle
ddev composer require doctrine/mongodb-odm-bundle doctrine/mongodb-odm
-
In your application
.envor other client, set the connection string:MONGODB_URL=mongodb://db:db@mongo:27017
Mongo Express can now be started on demand using the ddev mongo-express command.
| Command | Description |
|---|---|
ddev mongosh |
Run MongoDB Shell, see the documentation |
ddev mongo-express |
Start web-based MongoDB admin interface |
ddev describe |
View service status and used ports for MongoDB |
ddev logs -s mongo |
Check MongoDB logs |
ddev logs -s mongo-express |
Check Mongo Express logs (if it's started) |
- You can't define custom MongoDB configuration with this current setup.
- You can't use
ddev import-dbto import to mongo.
To change the Docker image:
ddev dotenv set .ddev/.env.mongo --mongo-docker-image=mongo:latest
ddev add-on get ddev/ddev-mongo
ddev restartMake sure to commit the .ddev/.env.mongo file to version control.
All customization options (use with caution):
| Variable | Flag | Default |
|---|---|---|
MONGO_DOCKER_IMAGE |
--mongo-docker-image |
mongo:latest |
MONGO_EXPRESS_DOCKER_IMAGE |
--mongo-express-docker-image |
mongo-express:1.0 |
MONGO_INITDB_ROOT_USERNAME |
--mongo-initdb-root-username |
db |
MONGO_INITDB_ROOT_PASSWORD |
--mongo-initdb-root-password |
db |
MONGO_INITDB_DATABASE |
--mongo-initdb-database |
db |
ME_CONFIG_MONGODB_URL |
--me-config-mongodb-url |
mongodb://db:db@mongo:27017 |
Originally contributed by @wtfred
Maintained by @julienloizelet