MongoDB replica set for Prisma on Railway

By Tracklayer · Updated 2026-11-20

Short answer: Prisma’s MongoDB connector needs MongoDB to run as a replica set, because it relies on transactions, and a standalone mongod rejects them. On Railway you can get one with a template that runs MongoDB 8.0 as a single-node replica set (rs0) and sets up the root user, keyFile and replica set on first boot. It also runs a daily backup job to a Railway Bucket. It has one member, so there is no failover.

Deploy MongoDB replica set on Railway

Why Prisma needs a replica set

A plain MongoDB container starts as a standalone server. A standalone mongod does not support multi-document transactions or change streams, so Prisma’s MongoDB connector, Mongoose sessions and watch() fail against it. A replica set enables both, and a replica set with a single member is enough for that purpose.

The same applies to anything in your app that needs transactions (orders, payments, inventory) or change streams (notifications, cache invalidation, sync).

Which MongoDB templates people deploy on Railway

TemplateCreatorDeploymentsServices
MongoDBRailway Templates40,7071
ExpressJS Mongooseopqr's Projects1,1692
LibreChat Private AI Chat (MongoDB + Meilisearch)Tracklayer85
MongoDB 8 Replica Set (Prisma-Ready) with BackupsTracklayer12

Railway marketplace data as of 2026-11-19. Full ranking: Best MongoDB templates on Railway.

Template names do not always say whether the database runs as a replica set, which version it pins or whether it has backups. Open the template page and read its services and description before you pick one.

Deploy MongoDB as a replica set, step by step

These steps use Tracklayer’s MongoDB 8 Replica Set (Prisma-Ready) with Backups template, which pins MongoDB Community Server 8.0.34 (the official mongo image).

  1. Deploy the template. It creates a MongoDB service with a volume at /data/db, a MongoDB Backup cron job and a Railway Bucket.
  2. Wait for the ready line. Open the MongoDB logs and look for [mongodb-rs-init] replica set rs0 ready: PRIMARY .... There is no healthcheck, because Railway healthchecks are HTTP-only.
  3. Find the credentials. They are generated. Open the MongoDB service, then Variables. The user is mongo, matching Railway’s own MongoDB template, and the variable names (MONGOHOST, MONGOPORT, MONGOUSER, MONGOPASSWORD, MONGO_URL) are the same.
  4. Check the replica set. From your machine, run mongosh with MONGO_PUBLIC_URL, then rs.status().members[0].stateStr. It should return PRIMARY.
  5. Connect your app. In your app service, add a variable that references the database:
    • Prisma: DATABASE_URL = ${{MongoDB.DATABASE_URL}}. It is the same URL with the database railway in the path.
    • Drivers and Mongoose: MONGO_URL = ${{MongoDB.MONGO_URL}}, which ends in /?replicaSet=rs0&authSource=admin.
  6. Point Prisma at it. Your schema reads the URL from the environment:
datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

To run prisma db push from your machine, use DATABASE_PUBLIC_URL. It goes through Railway’s TCP proxy. Proxy traffic is not encrypted and is billed as egress; delete the TCP proxy under Settings, Networking if you want the database private.

  1. Run the first backup. Run railway cron run --service "MongoDB Backup" or wait for 03:15 UTC, then check the Bucket’s Files tab.

Data, backups and upgrades

What it costs

Railway bills usage. The template’s own figures are estimates, not measurements, based on Railway’s published prices: about $2.50 per month idle and about $14.50 per month for a typical small app with 1 GB of RAM, a 5 GB volume and daily backups. A busier setup (4 GB RAM, 1 vCPU, 30 GB volume) is estimated at about $70. RAM and volume size drive most of it.

Limits and licence

Other options

For a relational alternative, Tracklayer also maintains Postgres 18 with pgvector. For other databases, see MongoDB templates on Railway and Postgres templates on Railway.

FAQ

Does Prisma 7 work with MongoDB?

According to the template README, which cites Prisma's docs as checked on 2026-10-31, MongoDB is not yet supported in Prisma ORM 7 and is early access in Prisma ORM 8 (it needs MongoDB 8.0 or newer). Prisma ORM 6.x is the line the README describes as working with a replica set. Check Prisma's current docs before you upgrade.

Does this setup have failover?

No. It is one replica-set member, so there is no failover. If you need automatic failover, the template README points to Railway's own Mongo HA template, which runs three members. You scale this one vertically by raising RAM, CPU and volume size, and you keep a single replica.

What licence does MongoDB use?

MongoDB Community Server is under the Server Side Public License v1 (SSPL). Using it as your app's database is common, but offering MongoDB itself as a service to third parties has conditions. This is not legal advice; ask a lawyer if your product resells database access.

How do I restore a backup?

Download mongodb.archive.gz from the Bucket and run mongorestore with --gzip, --drop and exclusions for admin.system.users and admin.system.roles. Alternatively set BACKUP_RESTORE_RUN to a run folder on the MongoDB Backup service and trigger the job, then clear the variable.

Why can't I connect from my laptop with the private URL?

The replica-set member is registered under the private hostname mongodb.railway.internal, which only resolves inside Railway. From your machine use MONGO_PUBLIC_URL or DATABASE_PUBLIC_URL, which go through the TCP proxy with directConnection=true. Do not add replicaSet= to those URLs.