• Register
0 votes

Problem :

When I was trying to run the Mongod in terminal I got below message :

2020-01-14T17:33:04.554+0700 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2020-01-14T17:33:04.554+0700 I CONTROL  [initandlisten] dbexit:  rc: 100

And after running mongo command I got below message :

MongoDB shell version: 3.0.3
connecting to: test
2020-01-14T17:34:26.679+0700 W NETWORK  Failed to connect to, reason: errno:111 Connection refused
2020-01-14T17:34:26.681+0700 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

I am using the Ubuntu 14.04 LTS 64 bit. How can I fix this issue?

6 5 3
7,540 points

2 Answers

0 votes

Solution :

The MongoDB needs a data directory to store data. The Default path is /data/db

When you start the MongoDB engine, it tries to search above directory which is missing in your case. So solution is to create this directory and assign the rwx permission to your user.

If you want to change your path of the data directory then you must specify it while starting the mongod server as below,

mongod --dbpath /data/<path> --port <port no> 

This will help you in starting your mongod server with your custom path and the port number.

9 7 4
38,600 points
0 votes

The error message you are getting is “Unable to create lock file: /data/db/mongod.lock errno: 13 Permission denied. The directory you are creating does not seem to have the correct permission and ownership. This required to be writeable by the users who run on the MongoDB process.

Check the permission and ownership:

To see the permission and ownership of the ‘/data/db/’ directory, that is what the permission and ownership should look like;

$ ls -ld /data/db/

drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31 /data/db/

The left side drwxr-xr-x  shows permission for users, groups, and others. Mongod mongod shows who owns the directory and which group that the directory belongs to.


If your ‘/data/db/’ directory does not have the permission and ownership above, then do this;

First, check what user and group your mongo user has;

# grep mongo /etc/passwd


you must have an entry for mongod in /etc/passwd, as it is a daemon.

sudo chmod 0755 /data/db

sudo chown -R 498:496 /data/db    # using the user-id , group-id

The user can also use the user-name and group-name as follows;

sudo chown -R mongod:mongod /data/db

That should make it work.

In the comments below, some people use this;

sudo chown -R $USER /data/db

sudo chmod -R go+w /data/db

The disadvantage is that the $USER is an account that has a login shell. Daemons ideally have not the shell for the security reasons, that’s why you see in the grep of the password file.

11 5 1
3,890 points

Related questions

0 votes
1 answer 1.1K views
Problem : When I tried to run Mongodb in terminal I got following message : exception in initandlisten: nonexistentpath: data directory /data/db not found., terminating
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 611 views
Problem : I had created /data/db in my root directory and ran ./mongod but getting below error : [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating [initandlisten] shutdown: going to ... .. [initandlisten] now exiting [initandlisten] shutting down with code:100 Have anybody faced above error? any clues to fix above error?
asked Jan 4 alecxe 7.5k points
0 votes
1 answer 18 views
Problem: I am the beginner to MongoDB. I had followed all the steps which are mention in MongoDB installation documents for the Ubuntu 16.04. I executed the following command: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv ... when I started my MongoDB then encountered an error as below: Failed to start mongod.service: Unit mongod.service not found.
asked Jul 29 Raphael Pacheco 4.9k points
0 votes
1 answer 9 views
I'm a newbie when it comes to Linux administration using bash... I was following a tutorial on how to install laravel 5.2 from here... installed it successfully... firstly I installed composer and ran the following command composer global require "laravel/installer" after this put ... the path Note: I have installed oh my zsh on my terminal... What do I have to do to get it working please help
asked Sep 13 Marivoke 530 points
1 vote
1 answer 12 views
Problem: Hello Kodlogs, I am a Linux user and currently running Ubuntu 18.04 LTS distribution on my machine. I&rsquo;ve written a sample python program and trying to execute it through the Linux terminal. My sample program is saved as samle.py and I put a command ... command not found Why this is happening? Could you please give a hint? How could I overcome the error? Thanks for enlightening me.
asked Aug 1 adamSw 11.3k points