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
Tags :
< PreviousNext >
old lock file: \data\db\mongod.lock, probably means unclean shutdownIndexJava MongoDB : Convert JSON data to DBObject
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Related Posts

Popular Posts