Skip to content
Live $100 credit at signup, up to $300 total Offer ends December 31, 2026 Get started →

MongoDB 8.0

MongoDB is a general-purpose, document-oriented NoSQL database that stores data as flexible JSON-like documents. It is well suited for applications that need rich queries, horizontal scaling, or schemas that evolve over time.

ComponentVersion
MongoDB Community8.0.x
Ubuntu24.04 LTS

You can optionally set these when deploying MongoDB from the marketplace. Leave any field blank to have a secure random value generated automatically.

VariableDescription
MONGO_INITDB_ROOT_USERNAMEMongoDB root username
MONGO_INITDB_ROOT_PASSWORDMongoDB root password
ssh ubuntu@<your-vm-ip>

On the first boot, a setup script runs automatically. It creates the superuser defined by MONGO_INITDB_ROOT_USERNAME, which defaults to admin, using the configured or generated password, and enables authentication. This takes under 60 seconds.

Track progress:

journalctl -u mongodb-first-boot.service -f

Wait for the service to exit, then disconnect and reconnect. On login, the MOTD reports the MongoDB version with a READY status once setup is complete.

sudo cat /etc/mongodb/credentials.txt

This file contains the admin username, password, and connection instructions. It is only readable by root. The following command reads the configured username from the file. mongosh then prompts for the password so it does not appear in the process list.

MONGO_USER=$(sudo awk '/^Username:/{print $NF}' /etc/mongodb/credentials.txt)
mongosh -u "$MONGO_USER" --authenticationDatabase admin

Expected output:

test>
# Check service status
systemctl status mongod
# Restart
sudo systemctl restart mongod
# View logs
sudo journalctl -u mongod -f

Configuration file: /etc/mongod.conf

Port 27017 is not open externally by default. UFW is enabled and allows SSH (port 22) only.

To allow access from a specific IP:

sudo ufw allow from <trusted-ip> to any port 27017

To connect without opening the firewall (recommended), use an SSH tunnel:

# Run this on your local machine
ssh -L 27017:localhost:27017 ubuntu@<your-vm-ip>
# Then connect locally using the username from /etc/mongodb/credentials.txt
mongosh -u <username> --authenticationDatabase admin