---
title: "Deploy MongoDB | (Just Updated) Official Community Server, Auth On, Data Survives Redeploys"
description: "Official MongoDB 8 server, auth on, volume-backed, private and TCP URLs"
category: "Storage"
url: https://railway.com/deploy/mongodb-or-just-updated-official-communi
---

# Deploy MongoDB | (Just Updated) Official Community Server, Auth On, Data Survives Redeploys

Official MongoDB 8 server, auth on, volume-backed, private and TCP URLs

**[Deploy MongoDB | (Just Updated) Official Community Server, Auth On, Data Survives Redeploys on Railway](https://railway.com/template/mongodb-or-just-updated-official-communi)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/mongodb-or-just-updated-official-communi/manifest.json

- **Creator:** SuperSlowSloth
- **Category:** Storage

## Template content

### mongodb

- **Image:** mongodb/mongodb-community-server:8.0.32-ubi9-slim@sha256:80e08a8978e6de2feffdfd553358fd3398d56f42baac8a030e21ee2bd5709e04
- **Start command:** `/bin/sh -c 'set -e; M=$(cat /sys/fs/cgroup/memory.max 2>/dev/null || echo max); if [ "$M" != max ]; then CM=$((M / 2 / 1048576)); [ "$CM" -lt 256 ] && CM=256; C=$(printf "%d.%02d" $((CM / 1024)) $(((CM % 1024) * 100 / 1024))); else C=0.50; fi; export MONGODB_INITDB_ROOT_USERNAME=admin MONGODB_INITDB_ROOT_PASSWORD="$MONGO_PASSWORD"; echo "[railway] uid=$(id -u) wiredTigerCacheGB=$C owner=$(stat -c %u:%g /data/db)"; exec /usr/local/bin/docker-entrypoint mongod --wiredTigerCacheSizeGB "$C"'`

## Documentation

# Deploy and Host MongoDB on Railway

MongoDB is the document database behind a large share of Node.js, Python and Go back ends. This
template runs the official MongoDB Community Server 8.0 as a single service from a digest-pinned
image, with the database port on a Railway TCP proxy and a Railway volume holding the data files.

## About Hosting MongoDB

- **Authentication is on from the first connection.** A root user named `admin` is created at first
  boot with a password generated per deploy. Anonymous clients are refused with `Unauthorized`.
- **Your data survives redeploys.** The data directory `/data/db` is a Railway volume. The start
  command runs the server as root so the root-owned volume is writable, and prints the user id and
  mount owner in the deploy log so you can confirm it.
- **Cache size follows your plan.** The WiredTiger cache is set from the container's memory limit
  (half of it), not from the host's RAM, so the server does not size itself for a machine it cannot use.
- **Two ways in.** Services in the same project use the private URL; clients elsewhere use the TCP
  proxy URL.

## Common Use Cases

- The primary database for a Node.js, Python or Go application
- A backing store for self-hosted apps that require MongoDB (Rocket.Chat, LibreChat, Appsmith)
- A development or staging database you can reach from your laptop with `mongosh`
- Prototyping document models without managing a server

## Dependencies for MongoDB Hosting

- One Railway volume for the data directory (created by the template)

### Deployment Dependencies

- MongoDB documentation: https://www.mongodb.com/docs/manual/
- Official image: https://hub.docker.com/r/mongodb/mongodb-community-server

### Implementation Details

| Variable | Purpose |
| --- | --- |
| `MONGO_PASSWORD` | Password of the `admin` user, generated per deploy. |
| `MONGO_PRIVATE_URL` | Connection string on the private network, for services in the same project. |
| `MONGO_PUBLIC_URL` | Connection string on the TCP proxy, for clients outside Railway. |

Connect from your machine:

```bash
mongosh "$MONGO_PUBLIC_URL"
```

## Why Deploy MongoDB on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your
infrastructure so you don't have to deal with configuration, while allowing you to vertically and
horizontally scale it.

By deploying MongoDB on Railway, you are one step closer to supporting a complete full-stack
application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [TimescaleDB](https://railway.com/deploy/timescaledb-railway-template) — A PostgreSQL-based time-series database for analytics on Railway.
- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway

Open this page in a browser: https://railway.com/deploy/mongodb-or-just-updated-official-communi
