Mongodb Data Directory /Data/Db Not Found

Mongod complains that there is no /data/db folder

You created the directory in the wrong place

/data/db means that it's directly under the '/' root directory, whereas you created 'data/db' (without the leading /) probably just inside another directory, such as the '/root' homedirectory.

You need to create this directory as root

Either you need to use sudo , e.g. sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db


Note:

MongoDB also has an option where you can create the data directory in another location, but that's generally not a good idea, because it just slightly complicates things such as DB recovery, because you always have to specify the db-path manually. I wouldn't recommend doing that.


Edit:

the error message you're getting is "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied". The directory you created doesn't seem to have the correct permissions and ownership --
it needs to be writable by the user who runs the MongoDB process.

To see the permissions and ownership of the '/data/db/' directory, do this:
(this is what the permissions 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 the permissions for the User, Group, and Others.
'mongod mongod' shows who owns the directory, and which group that directory belongs to.
Both are called 'mongod' in this case.

If your '/data/db' directory doesn't have the permissions and ownership above, 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 should have an entry for mongod in /etc/passwd , as it's a daemon.

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

You can also use the user-name and group-name, as follows:
(they can be found in /etc/passwd and /etc/group )

sudo chown -R mongod:mongod /data/db 

that should make it work..

In the comments below, some people used this:

sudo chown -R `id -u` /data/db
sudo chmod -R go+w /data/db

or

sudo chown -R $USER /data/db 
sudo chmod -R go+w /data/db

The disadvantage is that $USER is an account which has a login shell.
Daemons should ideally not have a shell for security reasons, that's why you see /bin/false in the grep of the password file above.

Check here to better understand the meaning of the directory permissions:

http://www.perlfect.com/articles/chmod.shtml

Maybe also check out one of the tutorials you can find via Google: "UNIX for beginners"

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

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!

mongodb 4 Data directory C:\data\db\ not found

I had the same issue but after I create the directory C:\data\db\ it just worked.

MongoDB Data directory /data/db not found

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

When you start MongoDB engine, it searches this directory which is missing in your case. Solution is create this directory and assign rwx permission to user.

If you want to change the path of your data directory then you should specify it while starting mongod server like,

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

This should help you start your mongod server with custom path and port.

I am trying to install MongoDB and I get this error Data directory C:\data\db\ not found., terminating

There is a space in your command

`mongod --dbpath C:\Program Files\MongoDB\Server\3.2\data\db`

It should be

mongod --dbpath "C:\Program Files\MongoDB\Server\3.2\data\db"

MongoDB data/db not found

You need to create this directory as root

Either you need to use sudo , e.g. sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db

MongoDB can't find data directory after upgrading to Mac OS 10.15 (Catalina)

This is the main error:

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

Catalina has a surprise change: it won't allow changes to the root directory (this was discussed in a forum thread as well):

% sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system

Unfortunately, this is not spelled out explicitly in Apple's Catalina release notes, other than a brief mention in Catalina features:

macOS Catalina runs in a dedicated, read-only system volume

Since the directory /data/db is coded as MongoDB default, a workaround is to specify a different dbpath that is not located on the root directory. For example:

mongod --dbpath ~/data/db

This will place MongoDB's data in your home directory. Just make sure that the path ~/data/db actually exists.

Alternative method

An alternative method is to follow the instructions at Install MongoDB Community Edition on macOS by leveraging brew:

brew tap mongodb/brew
brew install mongodb-community

This will create some additional files by default:

  • the configuration file (/usr/local/etc/mongod.conf)
  • the log directory path (/usr/local/var/log/mongodb)
  • the data directory path (/usr/local/var/mongodb)

To run mongod you can either:

  • Run the command manually from the command line (this can be aliased for convenience):

    mongod --config /usr/local/etc/mongod.conf
  • Run MongoDB as a service using brew services. Note that this will run MongoDB as a standalone node (not a replica set), so features that depends on the oplog e.g. changestreams will not work unless you modify the mongod configuration file:

    brew services start mongodb-community

I shut down mongodb server and now I can't start it again with mongod

When you run mongod then MongoDB process is started with default parameters, see https://docs.mongodb.com/manual/reference/program/mongod/

However, when you run systemctl start mongod then systemd loads service file /usr/lib/systemd/system/mongod.service (check with systemctl status mongod). When you check this service file then you see that process is started as mongod -f /etc/mongod.conf, i.e. it uses the config file /etc/mongod.conf.

The settings in this config file can be different than mongod default parameters, see What is the default database path for MongoDB?

Note, if you like to customize your Mongo service, then you should not edit service file /usr/lib/systemd/system/mongod.service directly. Instead, make a copy to /etc/systemd/system/mongod.service and modify this copy according to your preferences. Otherwise when you upgrade MongoDB, the installer may revert /usr/lib/systemd/system/mongod.service file to default values.

Folders in this answer apply to Redhat Linux, they may be different on Ubuntu. Have a look at your system documentation.



Related Topics



Leave a reply



Submit