Can't use mongodb password on docker install

Following this guide here: https://docs.rocket.chat/docs/deploy-with-docker-docker-compose
And this one: https://docs.rocket.chat/v1/docs/mongodb-uri-authentication

I can’t for the life of me set a password protected connection to mongodb. I know it runs in a container but still, not using a password doesn’t sound right.

This is what I’ve tried so far:

In my .env file, I added these lines;

MONGODB_ROOT_USERNAME=root
MONGODB_ROOT_PASSWORD=rootpass

In my compose.yml file, I made these changes:

service::rocketchat::    
environment:
      MONGO_URL: "mongodb://${MONGODB_ROOT_USERNAME}:${MONGODB_ROOT_PASSWORD}@${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/${MONGODB_DATABASE:-rocketchat}?authSource=admin&replicaSet=rs0"
      MONGO_OPLOG_URL: "mongodb://${MONGODB_ROOT_USERNAME}:${MONGODB_ROOT_PASSWORD}@${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/local?authSource=admin&replicaSet=rs0"

environment:
      MONGODB_REPLICA_SET_MODE: primary
      MONGODB_REPLICA_SET_NAME: rs0
      MONGODB_DATABASE: rocketchat
      ALLOW_EMPTY_PASSWORD: no
      MONGODB_ROOT_USERNAME: ${MONGODB_ROOT_USERNAME}
      MONGODB_ROOT_PASSWORD: ${MONGODB_ROOT_PASSWORD}
      MONGODB_PORT_NUMBER: ${MONGODB_PORT_NUMBER:-27017}
      MONGODB_ENABLE_JOURNAL: ${MONGODB_ENABLE_JOURNAL:-true}

Using this configuration this is the error I get:

rocketchat-1  | MongoTopologyClosedError: Topology is closed
rocketchat-1  |     at /app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/src/sdam/topology.ts:515:42
rocketchat-1  |     at processTicksAndRejections (node:internal/process/task_queues:95:5) {
rocketchat-1  |   [Symbol(errorLabels)]: Set(0) {}
rocketchat-1  | }
rocketchat-1  | MongoServerSelectionError: getaddrinfo EAI_AGAIN mongodb
rocketchat-1  |     at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/src/sdam/topology.ts:591:30)
rocketchat-1  |     at listOnTimeout (node:internal/timers:581:17)
rocketchat-1  |     at processTimers (node:internal/timers:519:7) {
rocketchat-1  |   reason: TopologyDescription {
rocketchat-1  |     type: 'ReplicaSetNoPrimary',
rocketchat-1  |     servers: Map(1) { 'mongodb:27017' => [ServerDescription] },
rocketchat-1  |     stale: false,
rocketchat-1  |     compatible: true,
rocketchat-1  |     heartbeatFrequencyMS: 10000,
rocketchat-1  |     localThresholdMS: 15,
rocketchat-1  |     setName: 'rs0',
rocketchat-1  |     maxElectionId: null,
rocketchat-1  |     maxSetVersion: null,
rocketchat-1  |     commonWireVersion: 0,
rocketchat-1  |     logicalSessionTimeoutMinutes: null
rocketchat-1  |   },
rocketchat-1  |   code: undefined,
rocketchat-1  |   [Symbol(errorLabels)]: Set(0) {}
rocketchat-1  | }
rocketchat-1  |
rocketchat-1  | packages/core-runtime.js:189
rocketchat-1  |             throw error;
rocketchat-1  |             ^
rocketchat-1  | errorClass [Error]: [An error occurred when creating an index for collection "users: Topology is closed]
rocketchat-1  |     at Collection.createIndexAsync (packages/mongo/collection.js:1140:15)
rocketchat-1  |     at processTicksAndRejections (node:internal/process/task_queues:95:5)
rocketchat-1  |     at module.wrapAsync.self (packages/accounts-password/password_server.js:1107:1) {
rocketchat-1  |   isClientSafe: true,
rocketchat-1  |   error: 'An error occurred when creating an index for collection "users: Topology is closed',
rocketchat-1  |   reason: undefined,
rocketchat-1  |   details: undefined,
rocketchat-1  |   errorType: 'Meteor.Error'
rocketchat-1  | }
rocketchat-1  |
rocketchat-1  | Node.js v20.17.0

Can you access the mongo in the container from outside?

If not then it’s less of an issue.

AFAIA the this is a mongo issue rather than a Rocket.Chat one.

You probably need to create the user/password in the correct collection in mongo DB

eg

Once you get it right and have checked the collection etc you can set up Rocket to use it.

Note a search here provided:

Which linked to this which probably provides your answer:

Note - I didn’t know the answer. I just spent some time searching and reading. It is how you can solve most issues…

1 Like