MongoDB - Getting Started Guide
MongoDB is a document-oriented NoSQL database designed for flexibility and scalability. Instead of tables and rows, it stores data as JSON-like documents – ideal for applications with evolving data structures. This server comes with MongoDB 8.0 fully configured with the admin password you specified during the order. mongo-express is included for web-based database management.
Step 1 – Verify MongoDB Works
Your server’s IP address and root password are shown in the Server Information section on the Overview tab of your server in the client portal. The application settings you entered when ordering, passwords included, are shown in the MongoDB Credentials card on the same tab. mongo-express is a web-based admin interface for MongoDB. Open https://your.server.ip/mongo-express in a browser to verify it works.
HTTPS without a domain. Since January 2026 Let’s Encrypt issues certificates for IP addresses (official announcement), so your server gets a real, browser-trusted certificate on first boot – before you connect any domain. Certificates of this kind are short-lived (about six days) and renew automatically. If your server is not reachable from the internet on port 80 (for example, it sits behind a router), the certificate cannot be issued – in that case the browser shows a warning for a self-signed certificate – accept it, or use http:// instead.
MongoDB admin login:
- Username:
admin - Password: the MongoDB Admin Password you entered during the order
With mongo-express you can browse databases, view and edit documents, run queries and manage collections without using the command line.
Database servers don’t need public internet access. For secure access, place the server on a private network behind a VyOS router and connect through a VPN on the router (WireGuard or OpenVPN, on the router’s Configuration tab) to reach MongoDB and mongo-express on the server’s private IP. On a private address the server does not get the IP certificate, so open mongo-express over http:// there – the VPN already encrypts the connection.
Firewall. If you turn on the Firewall for this server in the client portal, allow incoming TCP port 80 in its rules, along with 443 for mongo-express. Certificates renew over port 80 – the IP certificate every few days – and without that rule the certificate expires and the browser starts showing a warning.
Step 2 – Connect to MongoDB Remotely
MongoDB is configured to accept remote connections with authentication. You can connect from any application or tool:
mongosh "mongodb://admin:your_admin_password@your.server.ip:27017/admin"
Connection details for MongoDB GUI tools (MongoDB Compass, Studio 3T, etc.):
| Parameter | Value |
|---|---|
| Host | your.server.ip |
| Port | 27017 |
| Username | admin |
| Password | Admin Password (from order) |
| Auth Database | admin |
Connection string format:
mongodb://admin:your_admin_password@your.server.ip:27017/admin
Note: Port 27017 is the MongoDB wire protocol, not HTTP – it cannot be opened in a browser. Use a database client or the command above.
Step 3 – Enable SSL for mongo-express (Optional)
If you have a domain pointing to this server, you can enable HTTPS for mongo-express with a free Let’s Encrypt certificate. Connect via SSH and run:
ssh root@your.server.ip
/opt/setup/get-ssl.sh db.yourdomain.com
The script will verify DNS, obtain a certificate and configure Apache for HTTPS automatically. After completion, mongo-express is available at https://db.yourdomain.com/mongo-express.
Note: Make sure your domain’s A record points to the server IP before running the script. SSL is optional – mongo-express works fine over HTTP with IP address access.
Database Management
Creating Additional Databases and Users
You can create additional databases and users via mongo-express or SSH:
mongosh -u admin -p --authenticationDatabase admin
use newdb
db.createUser({
user: "newuser",
pwd: "strong_password",
roles: [{ role: "readWrite", db: "newdb" }]
})
Import and Export
Via mongo-express: Use the web interface to view and edit individual documents.
Via command line (recommended for bulk operations):
# Export entire database
mongodump -u admin -p your_admin_password --authenticationDatabase admin -d your_database -o /tmp/backup/
# Import database
mongorestore -u admin -p your_admin_password --authenticationDatabase admin -d your_database /tmp/backup/your_database/
# Export single collection to JSON
mongoexport -u admin -p your_admin_password --authenticationDatabase admin -d your_database -c your_collection -o collection.json
# Import JSON into collection
mongoimport -u admin -p your_admin_password --authenticationDatabase admin -d your_database -c your_collection --file collection.json
Post-Installation
Fail2Ban – Brute-Force Protection
Your server comes with Fail2Ban pre-configured to protect both SSH and mongo-express from brute-force attacks.
| Rule | Max Attempts | Ban Duration |
|---|---|---|
| SSH | 5 failed logins | 10 minutes |
| mongo-express | 5 failed logins | 1 hour |
Useful commands:
# Check banned IPs
fail2ban-client status mongo-express
fail2ban-client status sshd
# Unban an IP
fail2ban-client set mongo-express unbanip 1.2.3.4
If you accidentally lock yourself out, open the Console on your server’s Overview tab in the client portal and unban your IP.
Service Management
MongoDB, mongo-express and Apache run via systemd. Common commands:
# Check service status
systemctl status mongod
systemctl status mongo-express
systemctl status apache2
# Restart MongoDB
systemctl restart mongod
# View MongoDB logs
journalctl -u mongod -n 100
MongoDB Performance Tuning
WiredTiger cache is automatically set to 50% of RAM on first boot. To check the current value:
mongosh -u admin -p --authenticationDatabase admin --eval "db.serverStatus().wiredTiger.cache"
To adjust manually, edit /etc/mongod.conf (under storage.wiredTiger.engineConfig.cacheSizeGB) and restart MongoDB:
systemctl restart mongod
Server Credentials
MongoDB and mongo-express credentials are stored in /root/.mongo_credentials.
What’s Pre-Configured
- Authentication: MongoDB authorization enabled with SCRAM-SHA-256. Admin user has root privileges
- Remote access: MongoDB accepts connections from any IP on port 27017
- WiredTiger cache: Automatically tuned to 50% of available RAM on first boot
- Web interface: mongo-express runs behind Apache reverse proxy at /mongo-express
Software Included
| Component | Version |
|---|---|
| Ubuntu | 24.04 LTS |
| MongoDB | 8.0 Community |
| mongosh | included with MongoDB |
| mongo-express | Latest |
| Apache | 2.4 (reverse proxy) |
| Certbot | Latest |
| Fail2Ban | 1.0 |
Troubleshooting
| Problem | Solution |
|---|---|
| 403 Forbidden on mongo-express right after the server is created | mongo-express stays closed to visitors, and MongoDB accepts connections only from the server itself, until setup enables your password – wait a minute and reload. If the page still shows 403 after five minutes, setup did not complete: check /opt/setup/setup.log over SSH and reinstall the server with the Rebuild button on its Overview tab in the client portal |
| Can’t connect to MongoDB remotely | Check that port 27017 is not blocked by firewall. Verify the user exists and has correct authenticationDatabase |
| mongo-express shows 401 Unauthorized | Use username admin and the Admin Password from order. Credentials are in /root/.mongo_credentials |
| mongo-express page doesn’t load | Check service: systemctl status mongo-express. Restart: systemctl restart mongo-express |
| Authentication failed | Make sure to specify --authenticationDatabase admin. The admin user authenticates against the admin database |
| MongoDB won’t start | Check logs: journalctl -u mongod -n 50. Common cause: disk full (df -h /) or invalid YAML in mongod.conf |
| Forgot MongoDB admin password | SSH in and check /root/.mongo_credentials |
| Blocked by Fail2Ban | Use the Console on your server’s Overview tab in the client portal to unban your IP |
| Forgot root password | Use the Console on your server’s Overview tab in the client portal to reset it |