Skip to content

MongoDB on a VPS

Document NoSQL database

Category
Databases
Hosting
Databases
Author
MongoDB Inc.
License
SSPL-1.0
Version
9.0.2

The script is free · VPS from $4.63 per month · installs in about 60 seconds

Install over SSH

root@vps:~# command -v docker >/dev/null || curl -fsSL https://get.docker.com | sh; P=$(openssl rand -hex 16); echo "$P" > /root/mongodb-root-password && chmod 600 /root/mongodb-root-password && docker run -d --name mongodb --restart unless-stopped -p 127.0.0.1:27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=$P -v mongo-data:/data/db mongo:9

  • SystemUbuntu 24.04 · x86_64ok
  • Sourcegithub.com/mongodb/mongook
  • Version9.0.2ok
  • Port27017/tcplisten

✓ MongoDB 9.0.2 installed · about 60 seconds

root@vps:~#

Install command from the library. Output is shortened and may differ on your server.

What it is

  • NoSQL
  • Documents
  • Database
  • Node.js

MongoDB is a document database: data is stored as JSON-like documents without a rigid schema. It is popular in Node.js projects, Telegram bots and prototypes where the data structure changes often.

Your own MongoDB on a VPS removes the limits of the free Atlas tier and keeps data next to your app.

The command runs the official image with authentication enabled. The port is reachable only from the server, and the admin password is saved to /root/mongodb-root-password.

  • Documents without a rigid schema
  • Indexes, aggregations and full-text search
  • Replication (replica set)
  • Drivers for Node.js, Python, Go
  • Authentication enabled from the first start

Recommended plan

For MongoDB: at least 2 vCPU, 3 GB RAM and 45 GB NVMe.

Minimum to run
1 vCPU · 2 GB RAM · 10 GB disk
Systems
Ubuntu 22.04 · Ubuntu 24.04 · Debian 12

How to install

Three steps in the bot or one command over SSH; installation takes about 60 seconds.

  1. 01

    Choose a plan in the bot

    Open @ExpressHost_bot and pay for a VPS. The server will be ready in about 60 seconds.

  2. 02

    Add MongoDB

    At the “Add-ons” step pick the script from the library, or run it later: Server settings → Scripts.

  3. 03

    The admin user's password is in /root/mongodb-root-password

    The bot will send the server address and login details to the chat.

Manually over SSH

Connect to the server as root and run the command. Supported systems: Ubuntu 22.04, Ubuntu 24.04, Debian 12.

Install command
command -v docker >/dev/null || curl -fsSL https://get.docker.com | sh; P=$(openssl rand -hex 16); echo "$P" > /root/mongodb-root-password && chmod 600 /root/mongodb-root-password && docker run -d --name mongodb --restart unless-stopped -p 127.0.0.1:27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=$P -v mongo-data:/data/db mongo:9

Ports

MongoDB ports
PortProtocolPurpose
27017tcpDatabase connections (127.0.0.1 only)

After installation

  1. 1.The admin user's password is in /root/mongodb-root-password
  2. 2.Console: docker exec -it mongodb mongosh -u admin -p
  3. 3.Connection string for your app: mongodb://admin:PASSWORD@127.0.0.1:27017

MongoDB FAQ

Didn’t find an answer? Message @ExpressHost_SupportBot.

What license does MongoDB use?

Server Side Public License (SSPL). It is not a restriction for your own projects, but you may not resell MongoDB as a cloud service.

How do I connect from my computer?

Via an SSH tunnel: ssh -L 27017:127.0.0.1:27017 root@IP, then use Compass or mongosh on localhost.

Where is the data stored?

In the mongo-data Docker volume. Backup: docker exec mongodb mongodump -u admin -p PASSWORD --archive > backup.archive.

MongoDB installs at checkout — in the bot.