• Register
0 votes
147 views

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 127.0.0.1:27017, reason: errno:111 Connection refused
2020-01-14T17:34:26.681+0700 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), 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

Please log in or register to answer this question.

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.

Solution:

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

mongod:x:498:496:mongod:/var/lib/mongo:/bin/false

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 2
3,890 points

Related questions

0 votes
1 answer 1.3K views
1.3K 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 1K views
1K 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, 2020 alecxe 7.5k points
0 votes
1 answer 51 views
51 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 11 views
11 views
Problem Hi Kodlogs, I am getting following error on my Linux: sudo apt-get command not found How do I fix this?
asked Nov 3, 2020 hashq 1.1k points
0 votes
1 answer 61 views
61 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, 2020 Marivoke 530 points
1 vote
1 answer 15 views
15 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, 2020 adamSw 11.3k points
0 votes
1 answer 24 views
24 views
Problem How to count number of files in a directory on Linux?
asked Oct 31, 2020 hashq 1.1k points
1 vote
1 answer 47 views
47 views
Problem: I want to install one package named speech_tools-2.1-release.tar.gz. After I run the command ./configure in this package, it shows me a message:\ Configure: error: no acceptable C compiler found in $PATH See 'config.log' for more details Any solution would be much appreciated. Thanks.
asked Mar 10, 2020 Gavin 15.3k points
0 votes
1 answer 258 views
258 views
Problem: I am very new to php, mongodb and codeigniter. At this moment I am trying to connect the mongodb with the php codeigniter framework. I have already made changes in &ldquo;php.in file extension=php_mongodb.dll.&rdquo; I have also put that file in xampp/php/ext/ ... to MongoDB? Please Note: Currently I am using the php 7, xampp and mongo db is installed in my machine the 3.4 version.
asked Sep 3, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 399 views
399 views
Problem : I am trying to do the file upload & enter the data task into my MongoDB using a flask but I had below error when I filled my form & upload my image: &ldquo;Bad Request The browser (or proxy) sent a request that this server could ... mypassword, 'email': myemail, 'img_name': file_name})         return render_template('index.html')     else:         return render_template('index.html')
asked Jan 22, 2020 jwilliam 3.9k points