I just installed mongodb version 3.0.3, on Ubuntu. I edited the conf file to change the default data directory to "/home/user/mongodb", and gave it the following permissions:

drwxr-xr-x  4 mongodb mongodb  4096 May 29 23:26 mongodb

I haven't changed anything else in the conf file. When I try to start the mongod service as

sudo service mongod start

and connect to the shell via the mongo command, I get the following error

MongoDB shell version: 3.0.3
connecting to: test
2015-05-29T23:58:49.450+0200 W NETWORK  Failed to connect to, reason: errno:111 Connection refused
2015-05-29T23:58:49.452+0200 E QUERY    Error: couldn't connect to server (, connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

The log file says this, every time I try to start the server:

2015-05-30T00:01:02.552+0200 I CONTROL  ***** SERVER RESTARTED *****
2015-05-30T00:01:02.581+0200 I STORAGE  [initandlisten] exception in initAndListen std::exception: boost::filesystem::status: Permission denied: "/home/user/mongodb/storage.bson", terminating
2015-05-30T00:01:02.581+0200 I CONTROL  [initandlisten] dbexit:  rc: 100

As far as I can tell, the permissions are correct. What could be the problem?


user home directory as default can be read, write and listed only by his owner so other users (other that root user) can't event list content of home folder of other users. So you need to ensure that mongodb user has access to new provided directory. you can check that by using command like

namei -m /home/user/mongodb

output example

f: /home/scantlight/mongodb
  dr-xr-xr-x /
  drwxr-xr-x home
  drwx------ scantlight
  drwxr-xr-x mongodb

as you can see my home folder has rwx permission for me, owner ... other user has no permission so content of my home folder can't be event listed by other user (except root)

Of course you don't want to give write or read permission to other users on your home directory but you want that they can reach destination folder. Here is were x flag can be used. when x flag is set on file it means that that file can be executed, for this reason it's called execution flag ... but when this flag is set on folder and neither of r(read) or w(write) flag is set .. that means that other users o users in same group can pass trough this folder to reach a deeper situated folder.

So to ensure that mongodb user will be able to reach, read and write on /home/user/mongodb folder ... you home folder should have executable flag (x flag) set for all other users.

chmod -R o+x /home/user/mongodb

after this, previous output example should look like

f: /home/scantlight/mongodb
 dr-xr-xr-x /
 drwxr-xr-x home
 drwx-----x scantlight
 drwxr-xr-x mongodb

Note x permission for all other users ... if this will not help :) ... just check file permissions inside /home/user/mongodb folder maybe there is some issue with permissions of included files?

| improve this answer | |
  • 1
    Adding the executable flag on the home folder worked. – Jayanth May 30 '15 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.