roni_r97
roni_r97

Reputation: 81

Problem using and running brew services start [email protected]

I have MacOs Catalina version 10.15.5 and I installed mongoDB following the steps indicated at their site https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ using Homebrew. When I check my mongoDB if its correctly installed I use which mongo command and I get /usr/local/bin/mongo response. When I use mongo --version and mongod --version I get:

MongoDB shell version v4.2.7
git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

and

db version v4.2.7
git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

respectevely which I think it means its correctly installed and should work.

But when I open terminal and run the command brew services start [email protected] as indicated on the site I get:

Error: undefined method `resolve_alias' for Formula:Class
/usr/local/bin/brew-services.rb:154:in `service'
/usr/local/bin/brew-services.rb:203:in `check'
/usr/local/bin/brew-services.rb:193:in `run!'
/usr/local/bin/brew-services.rb:397:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/Homebrew/Library/Homebrew/utils.rb:81:in `require?'
/usr/local/Homebrew/Library/Homebrew/brew.rb:112:in `<main>'

NOTE: my brew is updated and upgraded successfully!

I searched on the internet any solution but I cant find anything that solves the problem... If anyone had faced similar problem please explain step by step and with details how you had solved it?!?!

If I directly run command mongod I get:

2020-06-04T01:19:41.351+0200 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-06-04T01:19:41.355+0200 W  ASIO     [main] No TransportLayer configured during NetworkInterface startup
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] MongoDB starting : pid=24712 port=27017 dbpath=/data/db 64-bit host=Air-de-Ruslan.home
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] db version v4.2.7
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] allocator: system
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] modules: none
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] build environment:
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten]     distarch: x86_64
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten]     target_arch: x86_64
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] options: {}
2020-06-04T01:19:41.355+0200 E  NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2020-06-04T01:19:41.355+0200 F  -        [initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 684
2020-06-04T01:19:41.355+0200 F  -        [initandlisten] 

***aborting after fassert() failure

and if I run directly command mongo I get:

MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-04T01:21:20.317+0200 E  QUERY    [js] 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:341:17
@(connect):2:6
2020-06-04T01:21:20.320+0200 F  -        [main] exception: connect failed
2020-06-04T01:21:20.320+0200 E  -        [main] exiting with code 1

Upvotes: 2

Views: 9461

Answers (3)

zaffer
zaffer

Reputation: 446

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/

Upvotes: 2

mrkhosravian
mrkhosravian

Reputation: 56

Tested on macos Big Sur and [email protected]

If you're using homebrew and upgraded to [email protected], you may encounter with error when starting the mongodb-community service.

Use rm -rf /usr/local/var/mongodb to remove previous dbpath folder if exists then create it again using cd /usr/local/var && mkdir mongodb.

Then brew services start mongodb-community should work fine.

Upvotes: 2

roni_r97
roni_r97

Reputation: 81

SOLVED

I had to remove /usr/local/bin/brew-services.rb with the command

rm /usr/local/bin/brew-services.rb it could ask for permissions so add sudo rm /usr/local/bin/brew-services.rb.

After that I tried running brew services start [email protected] and I got

Successfully started mongodb-community (label: homebrew.mxcl.mongodb-commu but when I put mongo from different terminal to start the shell I got Socket exception errorso I checked also the mongod.log file and I saw it was a socket issue so I tried

ls -ls /tmp/mongodb-27017.sock and I got

0 srwx------ 1 root root 0 June 04 14:51 /tmp/mongodb-27017.sock that means the owner is root and mongodb cant access it so I did

sudo rm -rf /tmp/mongodb-27017.sock

to delete the file and then start again mongodb with

brew services start [email protected] that created new .sock file whose owner is directly mongodb or the actual user whoami and when I checked again

ls -lsah /tmp/mongodb-27017.sock

I proved I am the owner and then I could open new terminal and run mongo and get in with enabled connection and use the shell!

Upvotes: 6

Related Questions