MongoDB is a document-oriented NoSQL database known for flexibility, scalability, and developer-friendly features. It stores data in JSON-like documents with dynamic schemas.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dokploy/dokploy/llms.txt
Use this file to discover all available pages before exploring further.
Creating a MongoDB Database
Navigate to Databases
In your Dokploy dashboard, select your environment and click Add Database > MongoDB.
Configure Basic Settings
Provide the basic information:
- Name: Display name for your database
- App Name: Internal DNS name (e.g.,
mongo-prod) - Description: Optional notes
- Docker Image: MongoDB version (default:
mongo:15)
Set Credentials
MongoDB requires authentication credentials:
MongoDB creates a user with root privileges. You can create additional users after deployment.
Optional: Enable Replica Sets
For production deployments, enable replica sets:
- Check Enable Replica Sets
- Provides high availability and data redundancy
- Required for transactions and change streams
Replica sets require additional configuration after deployment.
Connection Information
- Internal Connection
- External Connection
- Application Drivers
Applications in the same environment use internal DNS:Connection String Examples:
Configuration
Environment Variables
Customize MongoDB with environment variables:Resource Allocation
Recommended resources by workload:| Workload | Memory Reservation | Memory Limit | CPU Reservation | CPU Limit |
|---|---|---|---|---|
| Development | 256MB | 512MB | 0.1 | 0.25 |
| Small Application | 512MB | 1GB | 0.25 | 0.5 |
| Production | 1GB | 2GB | 0.5 | 1.0 |
| High Performance | 2GB | 8GB | 1.0 | 4.0 |
MongoDB benefits from more memory for caching. Allocate at least 1GB for production workloads.
Docker Image Versions
MongoDB version options:Database Operations
Lifecycle Management
- Start/Stop
- Reload
- Rebuild
Control database availability:Start:
- Status:
done - Accepts connections
- Loads data from volume
- Status:
idle - Closes connections gracefully
- Data persists in volume
- No resource usage
Volume Management
MongoDB stores data in a Docker volume:- Database files (WiredTiger)
- Collection data
- Indexes
- Journal files
- Configuration
Backup Configuration
See Database Backups for automated backup setup usingmongodump.
Advanced Configuration
Custom Startup Options
Command:Replica Set Configuration
If you enabled replica sets during creation:-
Connect to MongoDB:
-
Initialize replica set:
-
Verify status:
Health Check Configuration
Restart Policy
Common Use Cases
- Web Application
- Production with HA
- Analytics
Standard MongoDB for web apps:
Monitoring and Logs
View MongoDB logs:- Open your MongoDB service
- Go to Logs tab
- Monitor database activity
Troubleshooting
Authentication failed
Authentication failed
Common authentication issues:Symptoms:
Authentication failederrors- Cannot connect with credentials
- Verify password format (no special characters)
- Check
authSourcein connection string: - Ensure user was created correctly
- Try connecting without authentication first (if accessible)
Cannot connect
Cannot connect
Connection troubleshooting:
- Verify host: Use app name for internal connections
- Check port: 27017 internal, custom external
- Database status: Must be
done - Network: Same environment for internal access
Out of memory
Out of memory
MongoDB exceeding memory limits:
- Increase container memory
- Reduce WiredTiger cache:
- Limit concurrent operations:
- Consider upgrading resources
Slow queries
Slow queries
Performance optimization:
-
Create indexes:
-
Increase cache size:
-
Enable profiling:
-
Review explain plans:
Replica set issues
Replica set issues
If replica sets are not working:
-
Check initialization:
-
Verify configuration:
- Check connectivity between nodes
- Review logs for errors
- Ensure hostnames are resolvable
Best Practices
Security
- Use strong passwords: Generate random passwords
- Limit external access: Only expose when necessary
- Create specific users: Don’t use admin for applications
- Enable authentication: Always run with
--auth - Regular backups: Configure automated backups
Performance
- Index properly: Create indexes for frequent queries
- Monitor cache: Ensure adequate WiredTiger cache
- Use projections: Return only needed fields
- Avoid large documents: Keep documents under 16MB
- Connection pooling: Reuse connections in applications
Production Deployment
- Enable replica sets: For high availability
- Configure monitoring: Track performance metrics
- Set up alerts: Monitor errors and slow queries
- Regular backups: Daily automated backups
- Test disaster recovery: Practice restore procedures
MongoDB Compass
Connect to your MongoDB instance using MongoDB Compass GUI:- Download MongoDB Compass
- Use connection string:
- Explore collections, run queries, and analyze performance
Next Steps
Setup Backups
Configure automated MongoDB backups
Redis
Deploy a Redis cache