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.
Software included
Section titled “Software included”| Component | Version |
|---|---|
| MongoDB Community | 8.0.x |
| Ubuntu | 24.04 LTS |
Getting started
Section titled “Getting started”1. Connect to your VM
Section titled “1. Connect to your VM”ssh ubuntu@<your-vm-ip>2. Wait for first-boot configuration
Section titled “2. Wait for first-boot configuration”On the first boot, a setup script runs automatically. It creates an admin superuser with a
randomly generated password and enables authentication. This takes under 60 seconds.
Track progress:
journalctl -u mongodb-first-boot.service -fWait for the service to exit, then disconnect and reconnect. The MOTD on login shows
MONGODB 8.0.x — READY when the setup is complete.
3. Retrieve credentials
Section titled “3. Retrieve credentials”sudo cat /etc/mongodb/credentials.txtThis file contains the admin username, password, and connection instructions. It is only readable by root.
4. Connect to MongoDB
Section titled “4. Connect to MongoDB”MONGO_PASS=$(sudo awk '/^Password:/{print $NF}' /etc/mongodb/credentials.txt)mongosh -u admin -p "$MONGO_PASS" --authenticationDatabase adminExpected output:
test>Managing MongoDB
Section titled “Managing MongoDB”# Check service statussystemctl status mongod
# Restartsudo systemctl restart mongod
# View logssudo journalctl -u mongod -fConfiguration file: /etc/mongod.conf
Security
Section titled “Security”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 27017To connect without opening the firewall (recommended), use an SSH tunnel:
# Run this on your local machinessh -L 27017:localhost:27017 ubuntu@<your-vm-ip>
# Then connect locallymongosh -u admin -p "<password>" --authenticationDatabase admin