When running Mongodb got NonExistentPath: Data directory /data/db not found., terminating

Viewed 10565

The error generated when executed sudo mongod executed

2018-09-13T20:56:08.259+0530 I CONTROL  [initandlisten] MongoDB starting : pid=3419 port=27017 dbpath=/data/db 64-bit host=admin
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] db version v3.6.7    
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] git version: 2628472127e9f1826e02c665c1d93880a204075e
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] allocator: 
    tcmalloc
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] modules: none
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] build environment:
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten]     distmod: ubuntu1404
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten]     distarch: x86_64
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten]     target_arch: x86_64
        2018-09-13T20:56:08.260+0530 I CONTROL  [initandlisten] options: {}
        2018-09-13T20:56:08.312+0530 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
        2018-09-13T20:56:08.312+0530 I CONTROL  [initandlisten] now exiting
        2018-09-13T20:56:08.312+0530 I CONTROL  [initandlisten] shutting down with code:100

I'm a beginner in MEAN stack application development and stuck with this error. Please help me. Thanks in advance

4 Answers

This solution solves my problem

  1. Make a directory as

    sudo mkdir -p /data/db

  2. That will make a directory named as db and than try to start with commands

    sudo mongod

If you get another error or problem with starting mongod, You may find problem as

Failed to set up listener: SocketException: Address already in use If you find that another error than you have to kill the running process of mongod by typing to terminal as

ps ax | grep mongod

Find the mongod running port and kill the process.

sudo kill ps_number 

Another way is to make a specefic port when starting mongod as

sudo mongod --port 27018

Just run

sudo mkdir -p /data/db

On the machine running the mongoDB server

Before doing any of the other solutions see my answer here. Maybe your conf file is being rejected due to outdated options or format changes.

cd ~
mongod

All you need to do above step to prevent the error.

Don't run the mongod at different local disk location.

eg. My computer has two local disk:

1.) Local disk E: - drive : (When I run mongod on E: drive or on targeting any location on E local disk then I will get error message as)

Admin@DESKTOP-CJBHIMO MINGW64 /e/Full-Stack-Developer
$ mongod
...
{"t":{"$date":"2021-03-22T11:33:26.675+05:30"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory E:\\data\\db\\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
...
{"t":{"$date":"2021-03-22T11:33:26.677+05:30"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

{"error":"NonExistentPath: Data directory E:\data\db\ not found.

2.) Local disk C: - drive : (When I run mongod on C: drive, which I recommend to use, cause, we mostly do the installation of mongodb on C: drive as per the instruction. If in your case, you installed on another drive, then run mongod on that drive's folder on hyper. Eg. as I run mongod on C:

Admin@DESKTOP-CJBHIMO MINGW64 ~/Desktop
$ mongod

{"t":{"$date":"2021-03-22T00:52:23.840-07:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"C:/data/db/","storageEngine":"wiredTiger"}}
...
{"t":{"$date":"2021-03-22T11:34:59.300+05:30"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}

"msg":"Storage engine to use detected by data files","attr":{"dbpath":"C:/data/db/","storageEngine":"wiredTiger"}}

This whole example is based on windows 10. It runs successful on root directory cause it is inside C: disk. To get inside root directory :

Related