Last updated November 16, 2026
Is self-hosted MongoDB free?
Yes. MongoDB Community Server is free to download and run on your own server, with no limit on databases, data size or connections. It covers what most apps use: documents, indexes, aggregation, transactions and replica sets.
Since October 2018 the server has been licensed under the Server Side Public License (SSPL), not a classic open-source license. In practice:
- Allowed: running your own apps and your clients' apps on it, in production, for a business, at no cost.
- Not allowed without sharing your code: offering MongoDB itself as a service to third parties, the way Atlas does. The SSPL then requires you to release the source of the whole service stack under the same license.
What is paid: MongoDB Enterprise Advanced, a commercial license with support and enterprise security features. MongoDB does not publish its price.
Search and vector search: these used to be Atlas only. Since June 30, 2026, MongoDB Search and Vector Search are generally available for Community Edition too, through a separate process called mongot that you run next to the database. MongoDB's compatibility table lists Server 8.3 for current mongot releases, and mongot follows the database through change streams, which need a replica set. So vector search without Atlas is possible, but it is a second service to run, not a switch.
Self-hosted MongoDB vs Atlas: what it costs
Atlas bills by the hour. The monthly figures below assume a cluster that runs all month.
| Option | Per month | Per year | What you get |
|---|---|---|---|
| Self-hosted on a VPS | $6–12 | $72–144 | 2 to 4 GB RAM, the whole disk |
| Atlas Free (M0) | $0 | $0 | 512 MB storage, shared |
| Atlas Flex | $8–30 | $96–360 | 5 GB storage, shared |
| Atlas M10 | about $57 | about $683 | 2 GB RAM, 2 vCPUs, 10 GB storage |
| Atlas M20 | about $146 | about $1,750 | 4 GB RAM, 2 vCPUs, 20 GB storage |
The free tier is fine for a demo, but 512 MB fills up quickly. The first dedicated cluster, M10, costs about $683 a year for 2 GB of RAM. A VPS with twice that memory costs about $144 a year, and the same server can run your app next to the database.
With SSH Workbench, add $199 once or $9 a month. The first year on a $12 VPS then comes to about $343, half the price of an M10, and every year after costs only the server.
What you need
- A Linux VPS with a recent CPU. MongoDB 5.0 and later need AVX on x86_64 (Intel Haswell or later, AMD Bulldozer or later) and ARMv8.2-A on arm64. MongoDB asks for at least two real cores.
- Enough RAM for the cache. By default MongoDB's WiredTiger cache takes 50% of (RAM minus 1 GB), so 1.5 GB on a 4 GB server. MongoDB does not publish a minimum; 2 GB works for small apps, 4 GB gives the cache room to grow.
- A domain or subdomain, only if apps outside the server need to connect.
- Docker or Podman on the server.
Self-host MongoDB in one click with SSH Workbench
- Connect your server in SSH Workbench and open Apps, then Deploy app, and pick MongoDB.
- Under Who needs to connect to this database?, choose Just apps on this server (recommended). The port is bound to 127.0.0.1, and you reach it from your laptop or a GUI client over an SSH tunnel.
- If something outside the server needs it, such as an app on Vercel or AWS, choose External services instead and enter a domain whose A record points at the server. SSH Workbench adds TLS and gives you an encrypted connection string in the form
mongodb://user:password@host:port/?tls=true. - Pick Backups: None, Daily or Hourly. Daily keeps 7 days.
- Leave Performance on Tuned to size MongoDB for the server's RAM, or pick Conservative. Under Advanced you can choose version 8 or 7, set the connection limit and a CPU limit.
- Click Deploy. A 24-character root password is generated for you and shown once, so save it from the screen that appears after the deploy.
Self-host MongoDB with docker compose
If you would rather set it up by hand, this is a single MongoDB server with authentication, bound to localhost, with its data on a named volume:
services:
mongodb:
image: mongo:8
restart: unless-stopped
ports:
- "127.0.0.1:27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: change-me-to-a-long-password
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:Start it with docker compose up -d. With both root variables set, MongoDB starts with authentication on and creates the root user in the admin database. Binding to 127.0.0.1 keeps port 27017 closed to the internet. Need a starting point for a bigger stack? The docker compose generator writes one for you.
Connecting to self-hosted MongoDB
From apps on the same server, connect to 127.0.0.1 and the port. In a compose file, another service reaches it by name:
mongodb://admin:PASSWORD@mongodb:27017/?authSource=adminFrom your laptop, Compass or another GUI client, open an SSH tunnel, then connect to localhost:27017 as if the database were local:
ssh -N -L 27017:127.0.0.1:27017 user@your-serverFrom outside the server, use the TLS connection string from the External services option. Do not publish port 27017 to the internet without TLS and a password.
Backups
Back up with mongodump, which runs while the database stays online:
docker compose exec mongodb mongodump --archive --gzip \
-u admin -p PASSWORD --authenticationDatabase admin > backup.archive.gzRestore it into a running server with mongorestore. --drop replaces collections that already exist:
docker compose exec -T mongodb mongorestore --archive --gzip --drop \
-u admin -p PASSWORD --authenticationDatabase admin < backup.archive.gzSSH Workbench's daily or hourly backups use the same mongodump archive, and you can restore one from the Backups page. Copy backups off the server too, so a lost VPS does not take them with it.
Updating MongoDB
For a patch or minor release within the same major, pull and recreate:
docker compose pull
docker compose up -dMajor versions are stricter. MongoDB upgrades one major at a time, so 6.0 goes to 7.0 before 8.0. Before each step, check that featureCompatibilityVersion matches the version you are running, upgrade the image, then raise it:
db.adminCommand({ setFeatureCompatibilityVersion: "8.0", confirm: true })Once you raise it, you cannot go back to the older binary without MongoDB's support, so take a backup first. To move to a new major version in SSH Workbench, take a mongodump, deploy the new version and restore into it.
MongoDB without AVX on older CPUs
MongoDB 5.0 and later are built for CPUs with AVX. Some cheap VPS plans, old home servers and virtual machines with a generic CPU model do not pass it through, and the server then refuses to start. Check before you deploy:
grep -o -m1 avx /proc/cpuinfoNo output means no AVX. Your options:
- Change the VPS plan or the VM's CPU type. On a VM you control, pass the host CPU through (the
hostCPU type in Proxmox). This is the fix to prefer. - Run
mongo:4.4, the last release that runs without AVX. It reached end of life on February 29, 2024 and gets no security fixes, so keep it off the internet and treat it as a stopgap.
Troubleshooting
"WARNING: MongoDB 5.0+ requires a CPU with AVX support" and the container exits. The CPU has no AVX. See the section above, and the container keeps restarting guide for reading the logs.
"Authentication failed" after changing the password in docker compose. The root user is created only on the first start with an empty data folder. Changing MONGO_INITDB_ROOT_PASSWORD later does nothing. Log in with the old password and change it with db.changeUserPassword(), or remove the volume if the data is disposable.
"Connection refused" from another container. Inside a container, localhost means that container. Use the service name (mongodb:27017) on a shared compose network. From your laptop, open the SSH tunnel first.
The External services deploy says DNS does not point at this server. SSH Workbench checks that the domain's A record resolves to the server's IP before it deploys. If the domain is on Cloudflare, set that record to DNS only (grey cloud), because Cloudflare's proxy does not pass MongoDB's TCP traffic.
Self-hosting MongoDB: questions
What is the difference between MongoDB and MongoDB Atlas?
MongoDB is the database server itself, which you can download and run anywhere. Atlas is MongoDB, Inc.'s managed cloud service that runs that same server for you on AWS, Google Cloud or Azure, and adds hosted extras such as automated backups, monitoring and scaling. Your application code and drivers work the same against either, so you can move between them with mongodump and mongorestore.
Is MongoDB Atlas self hosted?
No. Atlas only runs on MongoDB's cloud accounts, so you cannot install Atlas on your own server. The closest thing is the mongodb/mongodb-atlas-local Docker image, which bundles the server with the search engine for local development, but MongoDB says it is for evaluation only and not a production target. For production on your own hardware, run MongoDB Community or Enterprise.
Is MongoDB Atlas still free?
The M0 cluster is still listed at $0 and "free forever", with 512 MB of storage on shared hardware. That covers a hobby project or a demo. Once you need more space or steady traffic, the next steps are Flex at $8 to $30 a month and dedicated clusters from about $57 a month.
Can you self host MongoDB on AWS?
Yes. Install MongoDB or run the Docker image on an EC2 instance, put the data on an EBS volume, and keep port 27017 closed in the security group. Current x86 instances have the AVX support MongoDB 5.0 and later need, and Graviton2 or newer meets the ARMv8.2-A requirement on arm64. The setup is the same as on any other Linux VPS.
How do I create a database and user with MongoDB docker compose?
Set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD for the root user, and MONGO_INITDB_DATABASE for the database your init scripts run against. Mount a .js file into /docker-entrypoint-initdb.d/ that calls db.createUser() for an app user with only the roles it needs. These run only on the first start with an empty data folder, so delete the volume if you need them to run again.
Related guides
MongoDB is a trademark of MongoDB, Inc.. SSH Workbench is not affiliated with or endorsed by MongoDB, Inc..
