Question

Mongo no longer connects

Posted June 23, 2017 33.6k views
MongoDB Ubuntu 16.04

MongoDB was running fine, but now it won’t connect. When I run mongo, I get this message:

MongoDB shell version: 3.2.12
connecting to: test
2017-06-23T01:56:34.256-0400 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2017-06-23T01:56:34.256-0400 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

I have tried restarting the mongod service, but that doesn’t help. Can you please guide me on how to debug this issue?

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers

@robynover
Can you delete this file and then launch mongo service: /tmp/mongodb-27017.sock

When you start mongo directly it starts with default options. If you look at your first error logs, you’ll see it’s set to /var/lib/mongodb

  • Thank you @hansen – deleting that file worked! If you’re up for it, I’d appreciate any additional info about why this might have happened or why this fix works. Thanks!

    • Can you post the entire /var/log/mongodb/mongod.log to www.pastebin.com and link it here.
      It usually happens when mongo crashes (or the entire server is hard rebooted), but without seeing all the logs, it’s hard to tell.
      But even with the logs, we might not find the solution - it depends on how well the logging was around the crash time.

        • The server ran out of available RAM at least once (2017-06-08T04:24:23.444+0000) - and it also looks like it had an unclean shutdown (crash or hard reboot) at least once (2017-06-08T10:55:16.809+0000)

          I know those dates are not today, but if something like that has happened before, then I would guess it could be the cause of today’s problems.
          To dig much deeper, we would also have to look at the syslog (and probably other logs too) going back the same period - but most setups don’t have logging going back that far unless specifically configured.

Thank you @hansen. I don’t have a mongodb.log but I do have mongod.log:

2017-06-23T01:48:28.663-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-06-23T01:48:28.663-0400 I CONTROL  [initandlisten]     distarch: x86_64
2017-06-23T01:48:28.663-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2017-06-23T01:48:28.663-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-06-23T01:48:28.720-0400 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2017-06-23T01:48:28.720-0400 I -        [initandlisten] Fatal Assertion 28578
2017-06-23T01:48:28.720-0400 I -        [initandlisten] 

***aborting after fassert() failure


2017-06-23T01:56:30.912-0400 I CONTROL  [main] ***** SERVER RESTARTED *****
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] MongoDB starting : pid=19105 port=27017 dbpath=/var/lib/mongodb 64-bit host=currency
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] db version v3.2.12
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] git version: ef3e1bc78e997f0d9f22f45aeb1d8e3b6ac14a14
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] modules: none
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] build environment:
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten]     distarch: x86_64
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2017-06-23T01:56:30.930-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-06-23T01:56:30.976-0400 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2017-06-23T01:56:30.976-0400 I -        [initandlisten] Fatal Assertion 28578
2017-06-23T01:56:30.976-0400 I -        [initandlisten] 

***aborting after fassert() failure
  • When I run mongod, this is what I get:

    2017-06-23T12:32:00.096-0400 I CONTROL  [initandlisten] MongoDB starting : pid=18915 port=27017 dbpath=/data/db 64-bit host=currency
    2017-06-23T12:32:00.097-0400 I CONTROL  [initandlisten] db version v3.2.12
    2017-06-23T12:32:00.097-0400 I CONTROL  [initandlisten] git version: ef3e1bc78e997f0d9f22f45aeb1d8e3b6ac14a14
    2017-06-23T12:32:00.097-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
    2017-06-23T12:32:00.097-0400 I CONTROL  [initandlisten] allocator: tcmalloc
    2017-06-23T12:32:00.097-0400 I CONTROL  [initandlisten] modules: none
    2017-06-23T12:32:00.098-0400 I CONTROL  [initandlisten] build environment:
    2017-06-23T12:32:00.098-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
    2017-06-23T12:32:00.098-0400 I CONTROL  [initandlisten]     distarch: x86_64
    2017-06-23T12:32:00.098-0400 I CONTROL  [initandlisten]     target_arch: x86_64
    2017-06-23T12:32:00.098-0400 I CONTROL  [initandlisten] options: {}
    2017-06-23T12:32:00.154-0400 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
    2017-06-23T12:32:00.155-0400 I CONTROL  [initandlisten] dbexit:  rc: 100
    
    • I see that it says “Data directory /data/db not found”, and indeed there is no such directory. However, it was working fine yesterday, so I don’t understand what could have happened. Could my data directory have been deleted remotely somehow?

I am getting a same error. deleted /tmp/mongodb-27017.sock file.
getting following error:

mongod
2019-10-23T08:50:08.484-0400 I CONTROL  [initandlisten] MongoDB starting : pid=2756 port=27017 dbpath=/data/db 64-bit host=AEC-logs-mongodb-512mb-nyc3-01
2019-10-23T08:50:08.484-0400 I CONTROL  [initandlisten] db version v3.2.19
2019-10-23T08:50:08.484-0400 I CONTROL  [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten] modules: none
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten] build environment:
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten]     distmod: ubuntu1404
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten]     distarch: x86_64
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2019-10-23T08:50:08.485-0400 I CONTROL  [initandlisten] options: {}
2019-10-23T08:50:08.511-0400 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-10-23T08:50:08.512-0400 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2019-10-23T08:50:08.512-0400 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
2019-10-23T08:50:08.512-0400 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2019-10-23T08:50:08.566-0400 I STORAGE  [initandlisten] dropping unused ident: index-0-3415813987516495599
2019-10-23T08:50:08.567-0400 I STORAGE  [initandlisten] dropping unused ident: index-1-3415813987516495599
2019-10-23T08:50:08.567-0400 I STORAGE  [initandlisten] dropping unused ident: index-2-3415813987516495599
2019-10-23T08:50:08.568-0400 I STORAGE  [initandlisten] dropping unused ident: index-3-3415813987516495599
2019-10-23T08:50:08.568-0400 I STORAGE  [initandlisten] dropping unused ident: index-4-3415813987516495599
2019-10-23T08:50:08.569-0400 I STORAGE  [initandlisten] dropping unused ident: index-5-3415813987516495599
2019-10-23T08:50:08.570-0400 I STORAGE  [initandlisten] dropping unused ident: index-6-3415813987516495599
2019-10-23T08:50:08.571-0400 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-10-23T08:50:08.571-0400 I CONTROL  [initandlisten] 
2019-10-23T08:50:08.571-0400 I -        [initandlisten] Fatal assertion 28579 UnsupportedFormat: Unable to find metadata for table:index-1--4778676036905453176 Index: {name: _id_, ns: local.customers} - version too new for this mongod. See http://dochub.mongodb.org/core/3.4-index-downgrade for detailed instructions on how to handle this error.
2019-10-23T08:50:08.572-0400 I -        [initandlisten] 

Submit an Answer