|
1 |
| -[](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml)  |
| 1 | +[](https://addons.ddev.com) |
| 2 | +[](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml?query=branch%3Amain) |
| 3 | +[](https://github.com/ddev/ddev-mongo/commits) |
| 4 | +[](https://github.com/ddev/ddev-mongo/releases/latest) |
2 | 5 |
|
3 |
| -## What is ddev-mongo? |
| 6 | +# DDEV Mongo |
4 | 7 |
|
5 |
| -This repository is an add-on that provides Mongo and Mongo Express for [DDEV](https://ddev.readthedocs.io/en/stable/). |
| 8 | +## Overview |
6 | 9 |
|
7 |
| -It's based on [MongoDb from Docker Hub](https://hub.docker.com/_/mongo?tab=description#-via-docker-stack-deploy-or-docker-compose), [DDEV custom compose files](https://ddev.readthedocs.io/en/stable/users/extend/custom-compose-files/) and [API Platform tutorial](https://api-platform.com/docs/core/mongodb/#enabling-mongodb-support). |
| 10 | +[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. |
8 | 11 |
|
9 |
| -## Installation |
10 |
| - |
11 |
| -For DDEV v1.23.5 or above run |
12 |
| - |
13 |
| -```bash |
14 |
| -ddev add-on get ddev/ddev-mongo |
15 |
| -``` |
| 12 | +This add-on integrates MongoDB and Mongo Express into your [DDEV](https://ddev.com/) project. |
16 | 13 |
|
17 |
| -For earlier versions of DDEV run |
| 14 | +It's based on [MongoDB from Docker Hub](https://hub.docker.com/_/mongo?tab=description), [DDEV custom compose files](https://ddev.readthedocs.io/en/stable/users/extend/custom-compose-files/) and [API Platform tutorial](https://api-platform.com/docs/core/mongodb/#enabling-mongodb-support). |
18 | 15 |
|
19 |
| -```bash |
20 |
| -ddev get ddev/ddev-mongo |
21 |
| -``` |
22 |
| - |
23 |
| -Then restart your project |
| 16 | +## Installation |
24 | 17 |
|
25 | 18 | ```bash
|
| 19 | +ddev add-on get ddev/ddev-mongo |
26 | 20 | ddev restart
|
27 | 21 | ```
|
28 | 22 |
|
| 23 | +After installation, make sure to commit the `.ddev` directory to version control. |
| 24 | + |
29 | 25 | ## Configuration
|
30 | 26 |
|
31 | 27 | 1. Your project will likely require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
|
32 | 28 | `ddev composer require doctrine/mongodb-odm-bundle:^4.0.0@beta doctrine/mongodb-odm:^2.0.0@beta`
|
33 | 29 |
|
34 | 30 | 2. In your application `.env` or other client, set the connection string:
|
35 | 31 |
|
36 |
| - ``` |
| 32 | + ```dotenv |
37 | 33 | MONGODB_URL=mongodb://db:db@mongo:27017
|
38 | 34 | ```
|
39 | 35 |
|
40 |
| -Mongo Express will now be accessible by running `ddev mongo-express` command. |
41 |
| - |
42 |
| -## Features |
43 |
| - |
44 |
| -### `ddev mongosh` command |
| 36 | +Mongo Express can now be started on demand using the `ddev mongo-express` command. (This optional feature is available starting from DDEV v1.24.4+.) |
45 | 37 |
|
46 |
| -This command will run the `mongosh` (mongoDB Shell) command in the `mongo` container. Please [read the documentation](https://www.mongodb.com/docs/mongodb-shell/) for more information. |
| 38 | +## Usage |
47 | 39 |
|
48 |
| -### `ddev mongo-express` command |
49 |
| - |
50 |
| -This command opens your browser to the Mongo Express page. |
| 40 | +| Command | Description | |
| 41 | +| ------- | ----------- | |
| 42 | +| `ddev mongosh` | Run MongoDB Shell, see the [documentation](https://www.mongodb.com/docs/mongodb-shell/) | |
| 43 | +| `ddev mongo-express` | Start web-based MongoDB admin interface | |
| 44 | +| `ddev describe` | View service status and used ports for MongoDB | |
| 45 | +| `ddev logs -s mongo` | Check MongoDB logs | |
| 46 | +| `ddev logs -s mongo-express` | Check Mongo Express logs (if it's started) | |
51 | 47 |
|
52 | 48 | ## Caveats:
|
53 | 49 |
|
54 |
| -- The php extension (phpX.X-mongodb) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. You may want to edit your config.yaml to do what you want and remove the config.mongo.yaml. |
| 50 | +- The php extension (`phpX.X-mongodb`) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. You may want to edit your `.ddev/config.yaml` to do what you want and remove the `.ddev/config.mongo.yaml`. |
55 | 51 | - You can't define custom MongoDB configuration with this current setup.
|
56 | 52 | - You can't use `ddev import-db` to import to mongo.
|
57 | 53 |
|
58 |
| -**Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/mongodb)** |
| 54 | +## Advanced Customization |
| 55 | + |
| 56 | +If you don't want to authenticate with the default admin user, create a new file `.ddev/docker-compose.mongo_extra.yaml`: |
| 57 | + |
| 58 | +```yaml |
| 59 | +services: |
| 60 | + mongo: |
| 61 | + environment: |
| 62 | + - MONGO_INITDB_ROOT_USERNAME= |
| 63 | + - MONGO_INITDB_ROOT_PASSWORD= |
| 64 | + mongo-express: |
| 65 | + environment: |
| 66 | + - ME_CONFIG_MONGODB_URL=mongodb://mongo:27017 |
| 67 | +``` |
| 68 | +
|
| 69 | +(Don't forget to update your application's `.env` file.) |
| 70 | + |
| 71 | +To change the Docker image: |
| 72 | + |
| 73 | +```bash |
| 74 | +ddev dotenv set .ddev/.env.mongo --mongo-docker-image=mongo:5-focal |
| 75 | +ddev add-on get ddev/ddev-mongo |
| 76 | +ddev restart |
| 77 | +``` |
| 78 | + |
| 79 | +Make sure to commit the `.ddev/.env.mongo` file to version control. |
| 80 | + |
| 81 | +All customization options (use with caution): |
| 82 | + |
| 83 | +| Variable | Flag | Default | |
| 84 | +| -------- | ---- | ------- | |
| 85 | +| `MONGO_DOCKER_IMAGE` | `--mongo-docker-image` | `mongo:5-focal` | |
| 86 | +| `MONGO_EXPRESS_DOCKER_IMAGE` | `--mongo-express-docker-image` | `mongo-express:1.0` | |
| 87 | + |
| 88 | +## Credits |
59 | 89 |
|
60 | 90 | **Originally contributed by [@wtfred](https://github.com/wtfred)**
|
61 | 91 |
|
|
0 commit comments