Rocket.chat: Failed to connect to MongoDB

Created on 25 Oct 2016  ·  8Comments  ·  Source: RocketChat/Rocket.Chat

Moved from being a comment on an old ticket to a proper ticket. The old ticket (#4448) was closed before the user confirmed that it's working.

Let me know if you need any more information, copy paste of my update follows:

This hasn't been solved. Just ran a clean install on a CentOS 7.2 minimal install:

[root@rocket-srv1 Rocket.Chat]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@rocket-srv1 Rocket.Chat]# which node
/bin/node
[root@rocket-srv1 Rocket.Chat]# node -v
v4.5.0
[root@rocket-srv1 Rocket.Chat]# 
[root@rocket-srv1 Rocket.Chat]# systemctl status mongod
● mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod)
   Active: active (running) since Thu 2016-10-13 14:03:21 CEST; 4min 47s ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 8191 (mongod)
   CGroup: /system.slice/mongod.service
           └─8191 /usr/bin/mongod -f /etc/mongod.conf

Oct 13 14:03:20 rocket-srv1.foo systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Oct 13 14:03:20 rocket-srv1.foo runuser[8187]: pam_unix(runuser:session): session opened for user mongod...d=0)
Oct 13 14:03:21 rocket-srv1.foo mongod[8178]: Starting mongod: [  OK  ]
Oct 13 14:03:21 rocket-srv1.foo systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..
Hint: Some lines were ellipsized, use -l to show in full.
[root@rocket-srv1 Rocket.Chat]# 
[root@rocket-srv1 Rocket.Chat] node main.js

/opt/Rocket.Chat/programs/server/node_modules/fibers/future.js:313
                                                throw(ex);
                                                ^
MongoError: failed to connect to server [localhost:27017] on first connect
    at Object.Future.wait (/opt/Rocket.Chat/programs/server/node_modules/fibers/future.js:449:15)
    at new MongoConnection (packages/mongo/mongo_driver.js:216:27)
    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
    at new Mongo.Collection (packages/mongo/collection.js:103:40)
    at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
    at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)
    at meteorInstall.node_modules.meteor.accounts-base.server_main.js (packages/accounts-base/server_main.js:9:12)
    at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
    - - - - -
    at [object Object].<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mo
ngodb-core/lib/topologies/server.js:313:35)                                                                          
    at emitOne (events.js:77:13)
    at [object Object].emit (events.js:169:7)
    at [object Object].<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mo
ngodb-core/lib/connection/pool.js:260:12)                                                                            
    at [object Object].g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at [object Object].emit (events.js:172:7)
    at Socket.<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-cor
e/lib/connection/connection.js:162:49)                                                                               
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)
[root@rocket-srv1 Rocket.Chat]# 

Can provide more logs and so on, or it might be something that I messed up.

Cheers,
Juraj

support

Most helpful comment

Have you set any environment variables prior to this? It looks like you're starting with out: MONGO_URL

All 8 comments

Have you set any environment variables prior to this? It looks like you're starting with out: MONGO_URL

Don't think I did, no. I'll check it tomorrow at the machine and drop an update here.

So an update. I followed the environment variables section from here:

https://rocket.chat/docs/installation/manual-installation/centos/

And this is the result:

[root@rocket-srv1 Rocket.Chat]# echo $PORT
3000
[root@rocket-srv1 Rocket.Chat]# echo $ROOT_URL
http://rocket-srv1.FOO.BAR:3000/
[root@rocket-srv1 Rocket.Chat]# echo $MONGO_URL
mongodb://localhost:27017/rocketchat
[root@rocket-srv1 Rocket.Chat]# node --version
v4.5.0
[root@rocket-srv1 Rocket.Chat]# node main.js

/opt/Rocket.Chat/programs/server/node_modules/fibers/future.js:313
                                                throw(ex);
                                                ^
MongoError: failed to connect to server [localhost:27017] on first connect
    at Object.Future.wait (/opt/Rocket.Chat/programs/server/node_modules/fibers/future.js:449:15)
    at new MongoConnection (packages/mongo/mongo_driver.js:216:27)
    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
    at new Mongo.Collection (packages/mongo/collection.js:103:40)
    at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
    at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)
    at meteorInstall.node_modules.meteor.accounts-base.server_main.js (packages/accounts-base/server_main.js:9:12)
    at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
    - - - - -
    at [object Object].<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mo)
    at emitOne (events.js:77:13)
    at [object Object].emit (events.js:169:7)
    at [object Object].<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mo)
    at [object Object].g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at [object Object].emit (events.js:172:7)
    at Socket.<anonymous> (/opt/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-cor)
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)

I've also tried replacing localhost with the FQDN, but no go. As in, the same error pops up. I've tried this with and without restarting MongoDB.

Cheers,
Juraj

@B2RN it seems that either localhost isn't defined (I doubt) or mongo isn't truly running. Try running the mongo command and see if its able to successfully connect using: mongo

@geekgonecrazy:

Your localhost comment made me take a closer look at /etc/hosts. Looks like the VM was misconfigured and WAS actually missing the entry For Some Reason. What that reason is I haven't the slightest. But I've added it, rebooted the machine, defined the env vars and it seems to be running now.

Appreciate the help,
Juraj

@B2RN awesome! Yeah, usually very rare for that to happen. But figured i'd call it out as a possibility. Glad you got it working!

I had set a LONG time ago mongodb://localhost:27017/your_db

I rebooted and Meteor wouldn't work. Go figure. I had forgotten I had done this. Clearing the enviro and rebooting works.

Havn't played with snaps until now, how did you get into the VM? I'm getting the same error and need to start mongo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

antn89 picture antn89  ·  3Comments

Buzzele picture Buzzele  ·  3Comments

marceloschmidt picture marceloschmidt  ·  3Comments

Buzzele picture Buzzele  ·  3Comments

sta-szek picture sta-szek  ·  3Comments