Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB not starting on Mac

Tags:

macos

mongodb

I installed MongoDB via Homebrew. Manually created the /data/db directory. Tried to run mongod command from Command Line, here's what happened :

Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ mongod
mongod --help for help and startup options
2014-04-24T09:18:12.949+0530 [initandlisten] MongoDB starting : pid=19900 port=27017 dbpath=/data/db 64-bit host=Sanjeet-Suhags-MacBook-Pro.local
2014-04-24T09:18:12.949+0530 [initandlisten] 
2014-04-24T09:18:12.949+0530 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-04-24T09:18:12.949+0530 [initandlisten] db version v2.6.0
2014-04-24T09:18:12.949+0530 [initandlisten] git version: nogitversion
2014-04-24T09:18:12.949+0530 [initandlisten] build info: Darwin minimavericks.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2014-04-24T09:18:12.949+0530 [initandlisten] allocator: tcmalloc
2014-04-24T09:18:12.949+0530 [initandlisten] options: {}
2014-04-24T09:18:12.949+0530 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2014-04-24T09:18:12.949+0530 [initandlisten] dbexit: 
2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to close listening sockets...
2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to flush diaglog...
2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to close sockets...
2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: waiting for fs preallocator...
2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: lock for final commit...
2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: final commit...
2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: closing all files...
2014-04-24T09:18:12.950+0530 [initandlisten] closeAllFiles() finished
2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: removing fs lock...
2014-04-24T09:18:12.950+0530 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2014-04-24T09:18:12.950+0530 [initandlisten] dbexit: really exiting now
Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ 

What's going wrong ?

EDIT

Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ ls -ld /data/db
drwxr-xr-x  2 root  wheel  68 Apr 24 09:15 /data/db
Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ whoami
sanjeetsuhag
Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ 
like image 958
Objective-J Avatar asked Feb 14 '23 03:02

Objective-J


2 Answers

The problem is that the files mongod is trying to write to are owned by root but you are running mongod as user sanjeetsuhag.

The correct fix would be to change ownership of the directory via command:

$ sudo chown -R sanjeetsuhag /data/db

This will make the directory and everything under it owned by the same user you are running mongod as, which will allow it to start.

like image 154
Asya Kamsky Avatar answered Feb 16 '23 03:02

Asya Kamsky


I have same issues. I installed MongoDB with homebrew.

I think it needs admin priveledges.

I used : sudo mongod and it worked fine for me. Please try it.

like image 33
Aditya Parmar Avatar answered Feb 16 '23 04:02

Aditya Parmar