MongoDB + Mongo Express
MongoDB NoSQL database with Mongo Express web-based admin interface.
Overview
MongoDB is a leading NoSQL document database that revolutionized data storage by introducing flexible, JSON-like documents instead of rigid table structures. Developed by MongoDB Inc. (formerly 10gen) in 2009, it emerged as a response to the limitations of traditional relational databases in handling modern application requirements like rapid schema evolution, horizontal scaling, and unstructured data. MongoDB stores data as BSON (Binary JSON) documents within collections, enabling developers to work with data structures that naturally align with their application objects.
This stack combines MongoDB's powerful document database with Mongo Express, a web-based administrative interface that provides intuitive database management capabilities. Mongo Express serves as a lightweight alternative to MongoDB Compass, offering database browsing, document editing, collection management, and query execution through a clean web interface. The combination eliminates the need for command-line database administration and provides both programmatic access through MongoDB's drivers and visual management through the web UI.
Developers building content management systems, e-commerce platforms, or applications with evolving data requirements will find this stack particularly valuable. Startups benefit from MongoDB's schema flexibility during rapid prototyping phases, while the Mongo Express interface enables non-technical team members to view and modify data without database expertise. This combination is ideal for development environments, small to medium production deployments, and scenarios where quick database inspection and modification capabilities are essential.
Key Features
- Flexible document schema allowing field addition/removal without migrations
- Aggregation framework for complex data analysis and transformation pipelines
- Web-based database administration through Mongo Express interface
- Multi-document ACID transactions for data consistency across operations
- Change streams for real-time application updates on data modifications
- Horizontal scaling capabilities with built-in sharding support
- Visual document editing and collection browsing in Mongo Express
- GridFS support for storing and retrieving large files within MongoDB
Common Use Cases
- 1Content management systems requiring flexible article and media metadata storage
- 2E-commerce platforms with varying product catalogs and attribute structures
- 3IoT data collection systems handling diverse sensor data formats
- 4Real-time analytics applications processing event streams and user interactions
- 5Development environments requiring quick database inspection and data modification
- 6Prototype applications where data models are still evolving
- 7Small team projects needing non-technical database access through web interface
Prerequisites
- Minimum 2GB RAM recommended for MongoDB optimal performance
- Available ports 27017 (MongoDB) and 8081 (Mongo Express) on host system
- Basic understanding of NoSQL concepts and document-based data structures
- Environment variables configured: MONGO_USER, MONGO_PASSWORD, ME_USER, ME_PASSWORD
- Docker and Docker Compose installed with network creation permissions
- Understanding of MongoDB connection strings for application integration
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 mongodb: 3 image: mongo:74 container_name: mongodb5 restart: unless-stopped6 environment: 7 MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER}8 MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}9 volumes: 10 - mongodb_data:/data/db11 ports: 12 - "27017:27017"13 networks: 14 - mongo-network1516 mongo-express: 17 image: mongo-express:latest18 container_name: mongo-express19 restart: unless-stopped20 environment: 21 ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER}22 ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD}23 ME_CONFIG_MONGODB_SERVER: mongodb24 ME_CONFIG_BASICAUTH_USERNAME: ${ME_USER}25 ME_CONFIG_BASICAUTH_PASSWORD: ${ME_PASSWORD}26 ports: 27 - "8081:8081"28 depends_on: 29 - mongodb30 networks: 31 - mongo-network3233volumes: 34 mongodb_data: 3536networks: 37 mongo-network: 38 driver: bridge.env Template
.env
1MONGO_USER=admin2MONGO_PASSWORD=changeme3ME_USER=admin4ME_PASSWORD=changemeUsage Notes
- 1Docs: https://www.mongodb.com/docs/ | Mongo Express: https://github.com/mongo-express/mongo-express
- 2Access Mongo Express at http://localhost:8081 with ME_USER/ME_PASSWORD
- 3Connection string: mongodb://MONGO_USER:MONGO_PASSWORD@localhost:27017
- 4Backup: docker exec mongodb mongodump --archive=/data/backup.gz --gzip
- 5For replica set, add --replSet rs0 to mongod command
- 6Data persisted in mongodb_data volume
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
mongodb
mongodb:
image: mongo:7
container_name: mongodb
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
volumes:
- mongodb_data:/data/db
ports:
- "27017:27017"
networks:
- mongo-network
mongo-express
mongo-express:
image: mongo-express:latest
container_name: mongo-express
restart: unless-stopped
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER}
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD}
ME_CONFIG_MONGODB_SERVER: mongodb
ME_CONFIG_BASICAUTH_USERNAME: ${ME_USER}
ME_CONFIG_BASICAUTH_PASSWORD: ${ME_PASSWORD}
ports:
- "8081:8081"
depends_on:
- mongodb
networks:
- mongo-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 mongodb:5 image: mongo:76 container_name: mongodb7 restart: unless-stopped8 environment:9 MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER}10 MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}11 volumes:12 - mongodb_data:/data/db13 ports:14 - "27017:27017"15 networks:16 - mongo-network1718 mongo-express:19 image: mongo-express:latest20 container_name: mongo-express21 restart: unless-stopped22 environment:23 ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USER}24 ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD}25 ME_CONFIG_MONGODB_SERVER: mongodb26 ME_CONFIG_BASICAUTH_USERNAME: ${ME_USER}27 ME_CONFIG_BASICAUTH_PASSWORD: ${ME_PASSWORD}28 ports:29 - "8081:8081"30 depends_on:31 - mongodb32 networks:33 - mongo-network3435volumes:36 mongodb_data:3738networks:39 mongo-network:40 driver: bridge41EOF4243# 2. Create the .env file44cat > .env << 'EOF'45MONGO_USER=admin46MONGO_PASSWORD=changeme47ME_USER=admin48ME_PASSWORD=changeme49EOF5051# 3. Start the services52docker compose up -d5354# 4. View logs55docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/mongodb-express/run | bashTroubleshooting
- Authentication failed connecting to MongoDB: Verify MONGO_USER and MONGO_PASSWORD environment variables match between services
- Mongo Express shows 'Cannot connect to database': Ensure MongoDB container is fully started before Mongo Express attempts connection
- Port 27017 already in use: Stop any local MongoDB installation or change the host port mapping in docker-compose.yml
- Mongo Express login fails: Check ME_CONFIG_BASICAUTH_USERNAME and ME_CONFIG_BASICAUTH_PASSWORD environment variables
- Data not persisting after container restart: Verify mongodb_data volume is properly mounted and Docker has write permissions
- Memory issues during large operations: Increase Docker memory limits or add MongoDB memory configuration parameters
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download