MongoDB
The Railway MongoDB database service allows you to provision and connect to a MongoDB database with zero configuration.
Deploy
You can add a MongoDB database via the CMD + K
menu or by clicking the + New
button on the Project Canvas.
Connect
There are two ways to connect to a MongoDB database:
- privately via Private Networking
- publicly via TCP Proxy
When you deploy your MongoDB database, you will have access to two environment variables that enable one of the two connection types (private or public).
As you create more services in your project, you can use Reference Variables to easily connect to the MongoDB database.
Private Networking
To access your MongoDB database from another service within the same project, you can use the connection string stored in the MONGO_PRIVATE_URL
environment variable.
This connection string uses Private Networking to route communication to your service over the private network.
TCP Proxy Connection
To access your MongoDB database over the public internet, you can use the connection string stored in the DATABASE_URL
environment variable available in the service.
This connection string uses the TCP Proxy connection to route communication to your service over the public internet.
You can also connect using mongo shell:
Variables
The following variables are included in the MongoDB service and can be referenced in other services:
MONGOHOST
MONGOPORT
MONGOUSER
MONGOPASSWORD
MONGO_URL
MONGO_PRIVATE_URL
Connect to your MongoDB container using your library of choice and supplying the appropriate environment variables.
Image
The MongoDB database service uses the mongo:latest docker image.
Custom Start Command
The MongoDB database service starts with the following Start Command to enable communication over Private Network: mongod --ipv6 --bind_ip ::,0.0.0.0
Changing System Variables
Tailor your MongoDB service to your needs by adding any variables relevant to the mongo:latest image.
Edit this file on GitHub