https://github.com/ddev/ddev-mongo
MongoDB NoSQL database support for DDEV
https://github.com/ddev/ddev-mongo
ddev-get
Last synced: 5 months ago
JSON representation
MongoDB NoSQL database support for DDEV
- Host: GitHub
- URL: https://github.com/ddev/ddev-mongo
- Owner: ddev
- License: apache-2.0
- Created: 2022-03-28T15:05:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2026-02-03T11:43:55.000Z (5 months ago)
- Last Synced: 2026-02-04T02:09:11.980Z (5 months ago)
- Topics: ddev-get
- Language: Shell
- Homepage:
- Size: 164 KB
- Stars: 7
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://addons.ddev.com)
[](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml?query=branch%3Amain)
[](https://github.com/ddev/ddev-mongo/commits)
[](https://github.com/ddev/ddev-mongo/releases/latest)
# DDEV Mongo
## Overview
[MongoDB](https://www.mongodb.com/) 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](https://ddev.com/) project.
It's based on [MongoDB from Docker Hub](https://hub.docker.com/_/mongo?tab=description), [DDEV custom compose files](https://docs.ddev.com/en/stable/users/extend/custom-compose-files/) and [API Platform tutorial](https://api-platform.com/docs/core/mongodb/#enabling-mongodb-support).
## Installation
```bash
ddev add-on get ddev/ddev-mongo
ddev restart
```
After installation, make sure to commit the `.ddev` directory to version control.
## Connection
By default, the database with the name `db` is created. You can connect to it using this connection string:
```text
mongodb://db:db@mongo:27017/db?authSource=admin
```
You can change the default database name, username, and password using env variables:
```bash
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:
```bash
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](https://github.com/doctrine/DoctrineMongoDBBundle)
```bash
ddev composer require doctrine/mongodb-odm-bundle doctrine/mongodb-odm
```
2. In your application `.env` or other client, set the connection string:
```dotenv
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](https://www.mongodb.com/docs/mongodb-shell/) |
| `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:
```bash
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](https://github.com/wtfred)**
**Maintained by [@julienloizelet](https://github.com/julienloizelet)**