3
votes

I recently completed the m001 basics course on Mongo University and connecting to Atlas with the connection string was not a problem. With experimenting I messed up and now I am not able to start mongo. The steps I followed are (from my root directory):

  1. brew doctor --verbose

to make sure Homebrew is running correctly and there were no issues.

HomeBrew version: 3.0.1,

macOs: 11.1,

Homebrew Cask Staging Location: /usr/local/Caskroom

Homebrew Cask Taps: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask (3823 casks)

/usr/bin/xattr

  1. brew cleanup

  2. brew update

  3. brew tap mongodb/brew Mongo Docs installation

  4. brew install [email protected]

Already downloaded: /Users/kevinturney/Library/Caches/Homebrew/downloads/269692f6b2d908000ecd7602021f4826947a782576c1fea760d25ece5ccbb521--mongodb-macos-x86_64-4.4.3.tgz

  1. brew services start [email protected]

Service mongodb-community already started, use brew services restart mongodb-community to restart.

  1. brew services restart mongodb-community

==> Successfully stopped mongodb-community (label: homebrew.mxcl.mongodb-community)

==> Successfully started mongodb-community (label: homebrew.mxcl.mongodb-community)

  1. kevinturney / $ brew services list

Here is the error:

Name Status User Plist
mongodb-community error kevinturney /Users/kevinturney/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql stopped
postgresql stopped
redis stopped
unbound stopped

I checked the processes,

MongDB University-processes

  1. ps -ef | grep mongo

501 10770 81999 0 10:34AM ttys007 0:00.00 grep mongo

  1. ps -ef | grep mongod

501 10776 81999 0 10:34AM ttys007 0:00.00 grep mongod

  1. ps -ef | grep mongos

01 10781 81999 0 10:34AM ttys007 0:00.00 grep mongos

  1. mongo --version

MongoDB shell version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
allocator: system
modules: enterprise
build environment:
distarch: x86_64
target_arch: x86_64

  1. mongod --version

db version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
allocator: system
modules: enterprise
build environment:
distarch: x86_64
target_arch: x86_64

When I run brew services start mongodb-community it successfully starts and then

mongo this is the result:

kevinturney / $ brew services start mongodb-community

==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)

kevinturney / $ mongo

MongoDB shell version v4.2.2<br/>
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br/>
2021-02-17T11:37:32.192-0500 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, <br/>connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17<br/>
@(connect):2:6
2021-02-17T11:37:32.195-0500 F  -        [main] exception: connect failed
2021-02-17T11:37:32.195-0500 E  -        [main] exiting with code 1

I followed a very similar StackOverflow question, went though mongo docs, uninstalled, reinstalled, Also, tried this great post I am not sure what to try next.

2
Have you found a solution to your problem? I'm facing the same issue. [email protected] works great but I cannot manage to get [email protected] service runningGreenTurtle
Ok, I've dumped all my databases, removed the mongodb data folder and reinstalled mongodb@4. After that the mongodb@4 service started successfully and I could restore all my dumps. Not the way it was supposed to upgrade my mongo version but finally it worked.GreenTurtle
Now I have the same trouble how to resolve it?hoanghuychh

2 Answers

1
votes

If you are using macOS Catalina / BigSur Above this fix will work:

Go to command line and execute these commands, you need to use SUDO else this will not work.

We first remove the folder mongodb,

sudo rm -rf /usr/local/var/mongodb

then, we add it manually,

cd /usr/local/var && mkdir mongodb

Now, we run the brew service as below, please mention the mongodb version at the end, as below:

brew services start [email protected]

If you get below response please restart the service,

Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.

To restart the service use below, please mention the mongodb version at the end:

brew services restart [email protected]

Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-commu
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu

Now we list all services, with below command:

brew services list

Output:

Name              Status  User       Plist
mongodb-community started xxx         homebrew.mxcl.mongodb-community.plist

Open your Terminal and type mongod –version to verify your installation.

0
votes

On MacOS Big Sur (tested for [email protected]), the following always returns an error (which means mongodb-community service will be loaded automatically) :

~ brew services start mongodb-community

mongodb-community error zaffer /Users/zaffer/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

By default mongodb-community configuration is stored in /usr/local/etc/mongod.conf

By default the dbpath parameter is set as /usr/local/var/mongodb

On analyzing the logs, I found that the problem is mostly related to permissions of this folder /usr/local/var/mongodb

The following worked for me :

~ cd /usr/local/var/mongodb
~ sudo chown -R $(whoami) .
~ cd ..
~ sudo chown -R $(whoami) mongodb
~ brew services restart mongodb-community

If you are still facing problems, I suggest changing file permissions of all files of this folder (/usr/local/var/mongodb) :

~ chmod -R 777 /usr/local/var/mongodb
~ brew services restart mongodb-community

or use sudo if permission is denied

~ sudo chmod -R 777 /usr/local/var/mongodb
~ brew services restart mongodb-community

If you are still facing issues, observe the errors when running mongod as a background process using one of the following :

~ mongod
~ mongod --dbpath /usr/local/var/mongodb
~ mongod --config /usr/local/etc/mongod.conf

You may also encounter problems when upgrading from a lower version of mongodb-community, for eg. upgrading from 3.6 to 5.0, in my case, I was inclined towards saving the existing databases, otherwise I could have created a new folder for mongodb data, and updated the dbpath in /usr/local/etc/mongod.conf configuration file.

The recommended way to do this is to do an incremental upgrade, i.e. upgrade from 3.6 to 4.0, then 4.0 to 4.4, then 4.4 to 5.0. What this does is it sets the recommended compatibility versions for migrating the data from one version to another. You can set the compatibility versions manually from mongodb shell using (for this, you need a working mongodb server):

> db.adminCommand( { setFeatureCompatibilityVersion: <version> } )

link to doc : https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/