Skip to content

About

MongoDB NoSQL database support for DDEV

Topics

Resources

Code of conduct

Contributing

Stars

7 stars

Watchers

4 watching

Forks

Repository files navigation

add-on registry tests last commit release

DDEV Mongo

Overview

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.

Installation

ddev add-on get ddev/ddev-mongo
ddev restart

After 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 restart

Connection

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=db

If 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

Configuration

  1. Your project will likely require the Doctrine MongoDB ODM bundle

    ddev composer require doctrine/mongodb-odm-bundle doctrine/mongodb-odm
  2. In your application .env or 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.

Usage

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)

Caveats:

  • You can't define custom MongoDB configuration with this current setup.
  • You can't use ddev import-db to import to mongo.

Advanced Customization

To change the Docker image:

ddev dotenv set .ddev/.env.mongo --mongo-docker-image=mongo:latest
ddev add-on get ddev/ddev-mongo
ddev restart

Make 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

Credits

Originally contributed by @wtfred

Maintained by @julienloizelet

About

MongoDB NoSQL database support for DDEV

Topics

Resources

Code of conduct

Contributing

Stars

7 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages