Main Tutorials

MongoDB : couldn’t open /data/db/yourdb.ns errno:13 Permission denied

Starting MongoDB server, it shows error “Permission denied” on one of the database and shutdown the server automatically.


$ mongod
Fri Mar  8 22:54:46 [initandlisten] MongoDB starting : pid=13492 
	port=27017 dbpath=/data/db/ 64-bit host=Yongs-MacBook-Air.local
//...
Fri Mar  8 22:54:46 [initandlisten] journal dir=/data/db/journal
Fri Mar  8 22:54:46 [initandlisten] recover : no journal files present, no recovery needed
Fri Mar  8 22:54:46 [initandlisten] couldn't open /data/db/yourdb.ns errno:13 Permission denied
Fri Mar  8 22:54:46 [initandlisten] error couldn't open file /data/db/yourdb.ns terminating
Fri Mar  8 22:54:46 dbexit: 
Fri Mar  8 22:54:46 [initandlisten] shutdown: going to close listening sockets...
Fri Mar  8 22:54:46 [initandlisten] shutdown: going to flush diaglog...
Fri Mar  8 22:54:46 [initandlisten] shutdown: going to close sockets...
Fri Mar  8 22:54:46 [initandlisten] shutdown: waiting for fs preallocator...
Fri Mar  8 22:54:46 [initandlisten] shutdown: lock for final commit...
Fri Mar  8 22:54:46 [initandlisten] shutdown: final commit...
Fri Mar  8 22:54:46 [initandlisten] shutdown: closing all files...
Fri Mar  8 22:54:46 [initandlisten] closeAllFiles() finished
Fri Mar  8 22:54:46 [initandlisten] journalCleanup...
Fri Mar  8 22:54:46 [initandlisten] removeJournalFiles
Fri Mar  8 22:54:46 [initandlisten] shutdown: removing fs lock...
Fri Mar  8 22:54:46 dbexit: really exiting now

Solution

The error message is showing that you do not have permission to access yourdb.ns database. Check the MongoDB data directory /data/db/ , the database yourdb.ns belongs to the root user.


$ ls -ls /data/db

      0 drwxr-xr-x  2 mkyong  wheel          68 Mar  8 22:54 journal
 131072 -rw-------  1 root    wheel    67108864 Mar  7 17:01 yourdb.0
 262144 -rw-------  1 root    wheel   134217728 Mar  7 16:15 yourdb.1
  32768 -rw-------  1 root    wheel    16777216 Mar  7 17:01 yourdb.ns

$whoami
mkyong

To fix it, assign permission to the database.


$ sudo chown -R mkyong /data/db

$ ls -ls /data/db

      0 drwxr-xr-x  2 mkyong  wheel          68 Mar  8 22:54 journal
 131072 -rw-------  1 mkyong  wheel    67108864 Mar  7 17:01 yourdb.0
 262144 -rw-------  1 mkyong  wheel   134217728 Mar  7 16:15 yourdb.1
  32768 -rw-------  1 mkyong  wheel    16777216 Mar  7 17:01 yourdb.ns

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Connor James Leech
9 years ago

you are my savior all things MongoDB