MongoDB URL Authentication

Prev Next

The connection between Rocket.Chat and MongoDB instance is achieved using a MongoDB connection string URL. MongoDB authentication is done with the username and password.

Adding the following snippet to your .env file does the trick:

MONGO_URL=mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

In your container, pass the MONGO_URL variable with the right values for the connection. Depending on the password you're using, you might need to escape some characters. Refer to the MongoDB documentation for more information.

Your docker-compose.yml file should look like this:

environment:
      - "MONGO_URL=mongodb://rctestuser:mymongopassword@mongo:27017/rocketchat?authSource=admin"
      - "MONGO_OPLOG_URL=mongodb://rctestuser:mymongopassword@mongo:27017/local?authSource=admin" # The `MONGO_OPLOG_URL` variable is not required. It has been deprecated and will be removed in version 8.0.0

If you are using docker run, it should look like this:

docker run \
-e "MONGO_URL=mongodb://rctestuser:mymongopassword@mongo:27017/rocketchat?authSource=admin" \
rocketchat/rocket.chat:X.X.X