19
2019-05-21T14:25:54.799+0300 I CONTROL  [initandlisten] options: {}
2019-05-21T14:25:54.800+0300 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2019-05-21T14:25:54.800+0300 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2019-05-21T14:25:54.800+0300 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2019-05-21T14:25:54.800+0300 I CONTROL  [initandlisten] now exiting
2019-05-21T14:25:54.800+0300 I CONTROL  [initandlisten] shutting down with code:100

How do I figure out about Data directory /data/db not found., terminating

Soumitri Pattnaik
  • 3,246
  • 4
  • 24
  • 42
Joshua Johns
  • 340
  • 1
  • 3
  • 10
  • 1
    Possible duplicate of [Mongod complains that there is no /data/db folder](https://stackoverflow.com/questions/7948789/mongod-complains-that-there-is-no-data-db-folder) – sheilak May 21 '19 at 11:54

3 Answers3

38

The problem is that by default, Mongo points to that /data/db folder, and it either forgets to create or set ownership of it on installation.

sudo mkdir -p /data/db/

And then, we’ll set the ownership of the folder to the user that’s going to start the mongod service. Since I only use if for local development in my computer, I set myself as the owner:

sudo chown `id -u` /data/db

Now, just running mongod should do the job. Hope that helps you!

  • 1
    I get `mkdir: /data/db/: Read-only file system`, it's changed on newer OSX https://stackoverflow.com/questions/58283257/mongodb-cant-find-data-directory-after-upgrading-to-mac-os-10-15-catalina – lko Mar 15 '22 at 23:09
35

I ran into this same issue a few days ago. I am using Mac OS. Apparently, there was a permission problem with having my data directory in the root of my home folder. So what i did was i just created a directory in a folder in a location where i definitely have permissions and then ran mongo db with the the --dbpath option set to that location. for example:

mongod --dbpath ~/documents/data/db

Hope this helps :D

AnonDevs
  • 351
  • 3
  • 3
  • This is for Catalina+ OSX https://stackoverflow.com/questions/58283257/mongodb-cant-find-data-directory-after-upgrading-to-mac-os-10-15-catalina – lko Mar 15 '22 at 23:09
0

Just create a new folder in the data directory (the disk which was given in the error - for me, suggested to create these folders on the E disk). First create data the create db folser in data. Then start mongod again.

ouflak
  • 2,458
  • 10
  • 44
  • 49