Cannot use Unix socket for MongoDB!


This is the command line for the mongod:
/home/lamp/.local/bin/mongod --dbpath /home/lamp/ --replSet rs01 --bind_ip "" --unixSocketPrefix /home/lamp/ --pidfilepath /home/lamp/ &>> /home/lamp/

I tried a freshly created database. After the initial creation I logged in to mongo shell with mongod --host "/home/lamp/" and ran rs.initiate({_id:"rs01",version:1,members:[{_id:0,host:"/home/lamp/"}]}).

Now here’s the issue. With these environment variables…

MONGO_URL: "mongodb:///home/lamp/",
MONGO_OPLOG_URL: "mongodb:///home/lamp/",

I get the following error:

0|Rocket.Chat  | { MongoParseError: No hostname or hostnames provided in connection string
0|Rocket.Chat  |     at parseConnectionString (/home/lamp/
0|Rocket.Chat  |     at connect (/home/lamp/
0|Rocket.Chat  |     at connectOp (/home/lamp/
0|Rocket.Chat  |     at executeOperation (/home/lamp/
0|Rocket.Chat  |     at MongoClient.connect (/home/lamp/
0|Rocket.Chat  |     at Function.MongoClient.connect (/home/lamp/
0|Rocket.Chat  |     at new MongoConnection (packages/mongo/mongo_driver.js:177:11)
0|Rocket.Chat  |     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
0|Rocket.Chat  |     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
0|Rocket.Chat  |     at Object.defaultRemoteCollectionDriver (packages/underscore.js:784:19)
0|Rocket.Chat  |     at new Collection (packages/mongo/collection.js:97:40)
0|Rocket.Chat  |     at new AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
0|Rocket.Chat  |     at new AccountsServer (packages/accounts-base/accounts_server.js:23:5)
0|Rocket.Chat  |     at server_main.js (packages/accounts-base/server_main.js:7:12)
0|Rocket.Chat  |     at fileEvaluate (packages/modules-runtime.js:336:7)
0|Rocket.Chat  |     at Module.require (packages/modules-runtime.js:238:14)
0|Rocket.Chat  |   name: 'MongoParseError',
0|Rocket.Chat  |   [Symbol(mongoErrorContextSymbol)]: {} }

And with these environment variables:

MONGO_URL: "mongodb://",
MONGO_OPLOG_URL: "mongodb://",

I get this error:

 0|Rocket.Chat  | { MongoError: no primary found in replicaset or invalid replica set name
0|Rocket.Chat  |     at /home/lamp/
0|Rocket.Chat  |     at Server.<anonymous> (/home/lamp/
0|Rocket.Chat  |     at Object.onceWrapper (events.js:315:30)
0|Rocket.Chat  |     at emitOne (events.js:116:13)
0|Rocket.Chat  |     at Server.emit (events.js:211:7)
0|Rocket.Chat  |     at /home/lamp/
0|Rocket.Chat  |     at /home/lamp/
0|Rocket.Chat  |     at _combinedTickCallback (internal/process/next_tick.js:132:7)
0|Rocket.Chat  |     at process._tickCallback (internal/process/next_tick.js:181:9) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }

I tried with and without the port number but no difference. And this worked fine with TCP hostname. How do I connect Rocket.Chat to MongoDB via Unix socket???

Server Setup Information

  • Version of Rocket.Chat Server: 1.3.2
  • Operating System: Ubuntu 18.04
  • Deployment Method: PM2 for Rocket.Chat, crontab/nohup for mongod
  • Number of Running Instances: 1
  • DB Replicaset Oplog: wat
  • NodeJS Version: 8.16.1
  • MongoDB Version: 4.2.0
  • Proxy: not using gateway yet
  • Firewalls involved: none

Any additional Information

wait wtf now i’m having the same issue with tcp:

MONGO_URL: "mongodb://localhost:27017/rocketchat?replicaSet=rs01",
MONGO_OPLOG_URL: "mongodb://localhost:27017/local?replicaSet=rs01",

MongoError: no primary found in replicaset or invalid replica set name

The only difference between now and when it was working last time is last time the replica set was also using the TCP hostname but now is using the Unix socket. And mongod does log one connection so it seems the nodejs mongodb client has an issue with that.

I think this may be a bug in the node.js mongodb driver so I opened a bug report there

Found solution!

And Rocket.Chat can pass options to the driver from an environment variable:

So all you’d need to do is add the environment variable MONGO_OPTIONS='{"useUnifiedTopology": true}'.

Although I already worked around this issue by using an lxc container. But maybe it will be helpful for someone else.