I followed the MongoDb Docs to setup my first MongoDb,

When I start MongoDB using the command

C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe

I get the following error

Solution 1

MongoDB needs a folder to store the database. Create a C:\data\db\ directory:

mkdir C:\data\db

and then start MongoDB:

C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe

Sometimes C:\data\db folder already exists due to previous installation. So if for this reason mongod.exe does not work, you may delete all the contents from C:\data\db folder and execute mongod.exeagain.

Solution 2

For macOS users to fix this issue:

You need to go through the following steps:

Create the db directory. This is where the Mongo data files will live. You can create the directory in the default location by running:

sudo mkdir -p /data/db

Make sure that the /data/db directory has the right permissions by running:

sudo chown -R `id -un` /data/db

You're all set now and you can run sudo mongod to start the Mongo server.

It's not working if you run only mongod


Solution 3

Same issue on my Mac (using Brew) solved using:

sudo mongod  

Solution 4

For macOS users take care of below issue:

if you installing MongoDB Community on macOS using .tgz Tarball

((Starting with macOS 10.15 Catalina, Apple restricts access to the MongoDB default data directory of /data/db. On macOS 10.15 Catalina, you must use a different data directory, such as /usr/local/var/mongodb.))

you can solve it as the following:

(MacOS Catalina onwards)

Apple created a new Volume in Catalina for security purposes. If youre on Catalina, you need to create the /data/db folder in System/Volumes/Data.

Use this command:

sudo mkdir -p /System/Volumes/Data/data/db

Then, use this command to give permissions:

sudo chown -R `id -un` /System/Volumes/Data/data/db

this will replace normal

sudo mkdir -p /data/db

Make sure that the /data/db directory has the right permissions by running:

sudo chown -R `id -un` /data/db

once you finish and start mongoDB you can use the following in terminal:

sudo mongod --dbpath /System/Volumes/Data/data/db

Solution 5

To change default db folder C:\data\db in windows, the command is:


For example:

\mongod --dbpath C:\myfolder

Solution 6

Mac Users

Instead of running MongoDB with:

sudo mongod

You can use mongod instead if you:

  1. Locate the data folder of mongodb (usually ~/data)
  2. Add permission to read + write with sudo chmod -R ugo+rw data

If you need to use sudo when running mongodb (sudo mongod), that means you don't have read and write permission on the mongodb data folder

Solution 7

Please take following steps:

  1. As other friends mentioned, you should make a directory first for your database data to be stored. This folder could be something like:


  2. From command line navigate to where you have installed mongodb and where mongod.exe resides. In my case the full path is:

    C:\Program Files\MongoDB\Server\3.4\bin

  3. From here run mongod.exe and pass it the path to the folder you created in step one using the flag --dbpath as follows:

    mongod.exe --dbpath "C:\mongo-data"

Please Note: If you are on windows it is necessary to use double-quotes ("") in the above to run properly.

In this way you will get something like the following:

2017-06-14T12:45:59.892+0430 I NETWORK  [thread1] waiting for connections on port 27017

If you use single quotes (' ') on windows, you will get:

2017-06-14T01:13:45.965-0700 I CONTROL  [initandlisten] shutting down with code:100

Hope it helps to resolve the issue.

Solution 8

To run Mongo DB demon with mongod command, you should have a database directory, probably you need to run:

mkdir C:\data\db

Also, MongoDB need to have a write permissions for that directory or it should be run with superuser permissions, like sudo mongod.

Solution 9

I kept getting the following error when I tried to start mongodb (on mac os).

"shutting down with code:100"

I was using the following command:

./mongod --dbpath=~/mongo-data

The fix for me was that I didn't need the "=" sign and this was causing the error. So I did

./mongod --dbpath ~/mongo-data

Just wanted to throw this out there because the error in no way specifies that this is the problem. I almost removed the contents of the ~/mongo-data directory to see if that helped. Glad I remembered that cli args sometimes do not use the "=" sign.

Solution 10

first you have to create data directory where MongoDB stores data. MongoDBs default data directory path is the absolute path \data\db on the drive from which you start MongoDB.

if you have install in C:/ drive then you have to create data\db directory. for doing this run command in cmd

C:\>mkdir data\db

To start MongoDB, run mongod.exe.

"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"

The --dbpath option points to your database directory.

Connect to MongoDB.

"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"

to check all work good :

show dbs

Solution 11

1.If it shows error (shutting down with code 100) that means it is not finding the desired location of file.

1.a If its before macOS Catalina then create directory with sudo mkdir -p /data/db and give permissions to use it
sudo chown -R id -un /data/db.

1.b if it macOS Catalina onwards then make sudo mkdir -p /System/Volumes/data/db and give it permissions sudo chown -R id -un /System/Volumes/data/db.

2.Starting mongo db brew services run mongodb-community

3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db

4.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things

4.a Either you change the port of mongod by specifying port
number mongod --dbpath /System/Volumes/Data/data/db port 27018.

4.b Or You can kill the process at that port by finding the process by sudo lsof -i :27017 and then kill by command
kill -9

5.Repeat the step 2 and 3.

Solution 12

In MacOS:-

If you forgot to give the path of the previously created database while running the mongo server, the above error will appear.

sudo ./mongod --dbpath ../../mongo-data/


Note :- ./mongod && ../../mongo-data is relative path. So you can avoid it by configuration in environment variable


Solution 13

For windows i've got same issue.

The fix was - i need to run command line as administrator.

Solution 14

if you already have the directory, check the dir permissions or try to restart mongo with sudo. sudo brew services start mongodb

Solution 15

In my case, I got a similar error and it was happening because I had run mongod with the root user and that had created a log file only accessible by the root. I could fix this by changing the ownership from root to the user you normally run mongod from. The log file was in /var/lib/mongodb/journal/

Solution 16

I you are using Virtualbox check your VM.

docker-machine ssh

df -h

Look at dev/sda1 if you do not have any free space this may be due to a large number of images, or containers. you can remove them using "docker rm" and "docker rmi"

Solution 17

This exit code will also be given if you are changing MongoDB versions and the data directory is incompatible, such as with a downgrade. Move the old directory elsewhere, and create a new directory (as per the instructions given in other answers).

Solution 18


It happened with me too because I stopped the MongoDB by the Task Manager.

Creating the C:\data\db folder and starting the MongoDB at C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe worked for me, as cespon suggested, but the MongoDB didn't show any of my Databases previously created.

Then, removing the C:\data\db folder and repairing the installation with the MongoDB installer, I recovered my data and started normally the MongoDB.

(I'm very new with MongoDB, but it helped me solve this problem and recover may previews data).

Solution 19

typed mongod and getting error


exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating

shuts down with Code 100

Then try with (create data and db folder with all permission)

mongod --dbpath=/data

use new tab and type mongo.

>use dbs

If still you are facing prob then you can check for mac catalina: (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/)

for windows: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows-unattended/