Connect ECONNREFUSED 127.0.0.1:27017

I’m receiving error connect ECONNREFUSED 127.0.0.1:27017 randomly today after my DB connection worked for over two years.

I updated brew and ran brew install mongodb-community@6.0, which worked. However, brew services start mongodb-community@6.0 gives me the below error:

    Bootstrap failed: 5: Input/output error

    Try re-running the command as root for richer errors.

    Error: Failure while executing; `/bin/launchctl bootstrap gui/501 
    /Users/chaseschlachter/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.

brew services restart mongodb-community@6.0 appears to work but when I run brew services list I see below:

Name              Status       User            File
mongodb-community error  15872 chaseschlachter ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

How do I reconnect my DB?

Hi @Chase_Schlachter, can you post the MongoDB log entries from the most recent time you tried to start the MongoDB sevice? Seeing this will help determine what is going on.

1 Like

Hi @Doug_Duncan - thanks for the reply. How would I pull the logs?

Hi @Chase_Schlachter,

Assuming you haven’t changed any paths from the Homebrew default, you can view the last lines in the log (eg last 20) with:

tail -n 20 $(brew --prefix)/var/log/mongodb/mongo.log

Or using grep with -C# to show lines of context before/after a pattern match:

grep -C5 “shutdown:” $(brew --prefix)/var/log/mongodb/mongo.log

What version of MongoDB were you running prior to the upgrade? In-place upgrades are only supported for adjacent major release series, so if you were not running MongoDB 5.0 prior to installing 6.0 I would expect find an error message like:

Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade.

You could look for the last instance of this specific message with:

grep “Failed to start” $(brew --prefix)/var/log/mongodb/mongo.log | tail -n1

Please see the MongoDB documentation for supported in-place upgrade procedures: https://www.mongodb.com/docs/manual/release-notes/6.0-upgrade-standalone/.

Regards,
Stennie

4 Likes

Hi @Stennie - thanks for the help with the logs. I installed the new Mac software update and now mongo shows as started when I run brew services list.

Name              Status  User            File
mongodb-community started chaseschlachter ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

I still can’t get the mongo command to work, though. I get the below error:

zsh: command not found: mongo

Here are the 20 rows of error logs from trying to run mongo:

tail -n 20 $(brew --prefix)/var/log/mongodb/mongo.log
{"t":{"$date":"2022-10-31T09:24:45.750-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn13","msg":"client metadata","attr":{"remote":"127.0.0.1:49453","client":"conn13","doc":{"driver":{"name":"nodejs","version":"4.8.1"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.5.0, LE (unified)|Node.js v16.5.0, LE (unified)","application":{"name":"MongoDB Compass"}}}}
{"t":{"$date":"2022-10-31T09:24:47.723-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49454","uuid":"6207768b-05d1-4a42-a22f-3068112739fb","connectionId":14,"connectionCount":14}}
{"t":{"$date":"2022-10-31T09:24:47.725-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn14","msg":"client metadata","attr":{"remote":"127.0.0.1:49454","client":"conn14","doc":{"driver":{"name":"nodejs","version":"4.8.1"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.5.0, LE (unified)|Node.js v16.5.0, LE (unified)","application":{"name":"MongoDB Compass"}}}}
{"t":{"$date":"2022-10-31T09:26:10.577-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49501","uuid":"468ae407-c512-4cbe-a831-63d379ea21cc","connectionId":15,"connectionCount":15}}
{"t":{"$date":"2022-10-31T09:26:10.615-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn15","msg":"client metadata","attr":{"remote":"127.0.0.1:49501","client":"conn15","doc":{"driver":{"name":"nodejs|mongosh","version":"4.10.0"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.18.0, LE (unified)","version":"4.10.0|1.6.0","application":{"name":"mongosh 1.6.0"}}}}
{"t":{"$date":"2022-10-31T09:26:10.639-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49502","uuid":"673f7969-7a2f-4d88-829a-a650fe91f3c3","connectionId":16,"connectionCount":16}}
{"t":{"$date":"2022-10-31T09:26:10.639-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49503","uuid":"b8181f23-ebf7-4592-9216-86f3a74b687e","connectionId":17,"connectionCount":17}}
{"t":{"$date":"2022-10-31T09:26:10.641-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn17","msg":"client metadata","attr":{"remote":"127.0.0.1:49503","client":"conn17","doc":{"driver":{"name":"nodejs|mongosh","version":"4.10.0"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.18.0, LE (unified)","version":"4.10.0|1.6.0","application":{"name":"mongosh 1.6.0"}}}}
{"t":{"$date":"2022-10-31T09:26:10.641-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn16","msg":"client metadata","attr":{"remote":"127.0.0.1:49502","client":"conn16","doc":{"driver":{"name":"nodejs|mongosh","version":"4.10.0"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.18.0, LE (unified)","version":"4.10.0|1.6.0","application":{"name":"mongosh 1.6.0"}}}}
{"t":{"$date":"2022-10-31T09:26:10.645-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49504","uuid":"bb0913c3-d75c-4367-878a-b0389f46aecf","connectionId":18,"connectionCount":18}}
{"t":{"$date":"2022-10-31T09:26:10.650-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn18","msg":"client metadata","attr":{"remote":"127.0.0.1:49504","client":"conn18","doc":{"driver":{"name":"nodejs|mongosh","version":"4.10.0"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.18.0, LE (unified)","version":"4.10.0|1.6.0","application":{"name":"mongosh 1.6.0"}}}}
{"t":{"$date":"2022-10-31T09:26:21.176-05:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49508","uuid":"578fbb45-591a-4fdc-af86-213e7a7a9312","connectionId":19,"connectionCount":19}}
{"t":{"$date":"2022-10-31T09:26:21.178-05:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn19","msg":"client metadata","attr":{"remote":"127.0.0.1:49508","client":"conn19","doc":{"driver":{"name":"nodejs|mongosh","version":"4.10.0"},"os":{"type":"Darwin","name":"darwin","architecture":"x64","version":"21.6.0"},"platform":"Node.js v16.18.0, LE (unified)","version":"4.10.0|1.6.0","application":{"name":"mongosh 1.6.0"}}}}
{"t":{"$date":"2022-10-31T09:28:05.381-05:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn19","msg":"Connection ended","attr":{"remote":"127.0.0.1:49508","uuid":"578fbb45-591a-4fdc-af86-213e7a7a9312","connectionId":19,"connectionCount":18}}
{"t":{"$date":"2022-10-31T09:28:05.422-05:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn17","msg":"Connection ended","attr":{"remote":"127.0.0.1:49503","uuid":"b8181f23-ebf7-4592-9216-86f3a74b687e","connectionId":17,"connectionCount":17}}
{"t":{"$date":"2022-10-31T09:28:05.422-05:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn18","msg":"Connection ended","attr":{"remote":"127.0.0.1:49504","uuid":"bb0913c3-d75c-4367-878a-b0389f46aecf","connectionId":18,"connectionCount":16}}
{"t":{"$date":"2022-10-31T09:28:05.424-05:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn16","msg":"Connection ended","attr":{"remote":"127.0.0.1:49502","uuid":"673f7969-7a2f-4d88-829a-a650fe91f3c3","connectionId":16,"connectionCount":15}}
{"t":{"$date":"2022-10-31T09:28:06.293-05:00"},"s":"W",  "c":"NETWORK",  "id":4615610, "ctx":"conn15","msg":"Failed to check socket connectivity","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"Connection closed by peer"}}}
{"t":{"$date":"2022-10-31T09:28:06.293-05:00"},"s":"I",  "c":"-",        "id":20883,   "ctx":"conn15","msg":"Interrupted operation as its client disconnected","attr":{"opId":3430}}
{"t":{"$date":"2022-10-31T09:28:06.299-05:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn15","msg":"Connection ended","attr":{"remote":"127.0.0.1:49501","uuid":"468ae407-c512-4cbe-a831-63d379ea21cc","connectionId":15,"connectionCount":14}}

Hi @Chase_Schlachter, starting with MongoDB 6.0 the mongo command is no longer installed (it was deprecated a couple versions back). You will want to use the new mongosh command line. This tool has most of the same functionality (most people won’t notice any difference).

1 Like

Thank you @Doug_Duncan , that worked.

I lost the data in my database but since it was test data I don’t have any problem repopulating. I’m not totally sure what prompted this connection interruption but my concern would be more around this happening in my production environment with customer data but it looks like I can manage with frequent db backups. Thank you!

It’s interesting that you lost data. Whenever I’ve used brew to update my version of MongoDB it’s never touched the data directory and the new version comes up just find pointed at the old data storage.

I even just now ran a brew uninstall mongodb-community and my data folder was not deleted. Once I ran brew install mongodb-community and connected via mongosh I was able to see the data.

Hi @Chase_Schlachter,

Upgrade/downgrade should not remove any existing data files.

I suspect you may have had a different dbPath for your previous installation. Try using Spotlight search to look for WiredTiger.wt which should be present in a MongoDB dbPath or use the command line equivalent: mdfind -name WiredTiger.wt.

Regards,
Stennie