Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Getting Started With MongoDB Setting Up MongoDB

MONGO ~Permission denied Is a mongo instance already running?

I’ve just changed the permissions with: sudo chmod 777 /data/db

But it keeps setting this error:

2015-12-29T15:31:22.043-0600 I CONTROL  [initandlisten] MongoDB starting : pid=2220 port=27017 dbpath=/data/db 64-bit host=MacBook-Air-de-Cesar-3.local
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] db version v3.2.0
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] allocator: system
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] modules: none
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] build environment:
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten]     distarch: x86_64
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten]     target_arch: x86_64
2015-12-29T15:31:22.044-0600 I CONTROL  [initandlisten] options: {}
2015-12-29T15:31:22.044-0600 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2015-12-29T15:31:22.045-0600 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2015-12-29T15:31:22.045-0600 I CONTROL  [initandlisten] debit:  rc: 100

Also in the browser with i run says

This webpage is not available ERR_CONNECTION_REFUSED

Anthony c
Anthony c
20,907 Points

Try this: https://gist.github.com/adamgibbons/cc7b263ab3d52924d83b

I want to say these are what did it for me:

sudo chmod 0755 /data/db sudo chown $USER /data/db

But honestly, I'm not sure. "mongod" all the sudden worked after I used the above two sudos (and made the "mkdir -p /data/db".

Note: I installed with homebrew

And I'm not sure mongo is serving anything to the browser, so I think it's okay that you see the err_connection there.

It stills not working, if I inspect the folder the permissions still being system: ‘Read and write’, weel: ‘read only’, everyone ‘read only’, I’ve used Mongo, but just in my users’s directories, not in the system files.

 Tony Mikel
 Tony Mikel
10,661 Points

Did you install with homebrew or manually?

Hombrew :)

2 Answers

Jack Blankenship
.a{fill-rule:evenodd;}techdegree seal-36
Jack Blankenship
Full Stack JavaScript Techdegree Graduate 39,036 Points

I was having the same issues until I ran

sudo chown -R 'youruserid' /data/db

it seems some file(s) in the directory still had the wrong permissions.

Great! Thanks!

16,963 Points

I spent an hour looking for this on the stackoverflow and came here to post my solution. Why didn't I just look here first...

I’ve just changed the permissions with: sudo chmod 777 /data/db - worked for me. Thanks.