3

Whenever I try to execute the command mongo from my terminal, this errors pops up:

MongoDB shell version v4.4.0 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:362:17 @(connect):2:6 exception: connect failed exiting with code 1 

I've been following this tutorial in order to install mongo on my MacBook Pro and failed by creating the /data/db. Later, this other article appeared upon me. The second one orders me to run the next piece of code from my terminal:

mongo — dbpath /System/Volumes/Data/data/db 

But the same error that I pasted at the begining appears.

Is there anything I can do to install and keep mongo running?

OS: macOS Catalina - 10.15.16

Thanks in advance!

4
  • That looks like a typo in that blog. the command should probably have been mongod --dbpath ... Commented Aug 11, 2020 at 20:56
  • @Joe That way it throws a: Invalid command: —-dbpath Commented Aug 11, 2020 at 21:00
  • You can also refer these Install MongoDB tutorial (pick the appropriate one) and verify your installation, startup and connecting with mongo shell. Commented Aug 12, 2020 at 1:51
  • I started with that one and it leaded me to the same thing. Commented Aug 12, 2020 at 12:43

3 Answers 3

1

Try to:

brew services start mongodb/brew/mongodb-community 
Sign up to request clarification or add additional context in comments.

Comments

1

For macOS user:

1、reinstall mongodb-community

brew uninstall mongodb-community brew cleanup brew install mongodb/brew/mongodb-community 

2、config and start

sudo mongod --config /usr/local/etc/mongod.conf brew services start mongodb-community 

Comments

0

To investigate while MongoDB service was failing to respond on MacOS, I checked the status of the service:

brew services list

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

I thus stopped the service

brew services stop mongodb-community

Then restarted it in verbose mode:

brew services start mongodb-community --verbose

==> Generated service file for mongodb-community: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>homebrew.mxcl.mongodb-community</string> <key>ProgramArguments</key> <array> <string>/opt/homebrew/opt/mongodb-community/bin/mongod</string> <string>--config</string> <string>/opt/homebrew/etc/mongod.conf</string> [...] 

This gave me the path to mongo conf, which I read
cat /opt/homebrew/etc/mongod.conf

systemLog: destination: file path: /opt/homebrew/var/log/mongodb/mongo.log logAppend: true 

I could then check the errors encountered while mongo was trying to start:

tail -n 100 /opt/homebrew/var/log/mongodb/mongo.log

In my case, it was clearly due to a version problem:

{ "t": { "$date": "2025-08-28T14:31:48.133+02:00" }, "s": "F", "c": "CONTROL", "id": 20573, "ctx": "initandlisten", "msg": "Wrong mongod version", "attr": { "error": "UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: Location4926900: Invalid featureCompatibilityVersion document in admin.system.version: { _id: \"featureCompatibilityVersion\", version: \"7.0\" }. See https://docs.mongodb.com/master/release-notes/8.0-compatibility/#feature-compatibility. :: caused by :: Invalid feature compatibility version value '7.0'. Expected one of the following versions: ''8.2', '8.1', '8.0'. See https://docs.mongodb.com/master/release-notes/8.0-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 8.0, see the documentation on upgrading at https://docs.mongodb.com/master/release-notes/8.0/#upgrade-procedures." } } 

A few lines on upgrading from 7.0 to 8.0:

brew services stop [email protected] brew uninstall [email protected] brew install [email protected] brew services start [email protected] mongosh 

Then in mongoshell:

use admin db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 }) 

which gives me

{ featureCompatibilityVersion: { version: '7.0' }, ok: 1 } 

I thus set version to 8

db.adminCommand({ setFeatureCompatibilityVersion: "8.0" }) 
{ "ok" : 1 } 

and checked:

db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 }) 
{ "featureCompatibilityVersion" : { "version" : "8.0" }, "ok" : 1 } 
db.version() 
8.0.13 

Then 8.0 to 8.2 First, quit mongosh: we'll upgrade mongo

brew unpin [email protected] brew services stop mongodb-community brew services stop [email protected] brew services stop [email protected] rm ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist rm ~/Library/LaunchAgents/[email protected] 2>/dev/null brew reinstall mongodb-community brew services start mongodb-community brew services list 

You should now have something like:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.