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.
By 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