Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

mongod stops with: dbpath (/data/db) does not exist

ErrorERROR: dbpath (/data/db) does not exist.

Short answer

mongod uses /data/db as its data folder unless told otherwise, and it does not create the folder. Either create a folder you own and pass it with --dbpath, or start MongoDB the way the installer set it up (a service or a config file), which already points at its own data folder.

  • Applies to MongoDB 9.0, macOS 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See whether the default folder exists, and whether MongoDB was installed with a package manager that gives it a config file.

    ls -ld /data/db
    brew list --versions | grep mongodb
  2. 2Match what you see, then jump to its fix

    1. 1dbpath (/data/db) does not existYou started mongod by hand and the default folder was never createdFix
    2. 2brew list shows mongodb-community, yet mongod falls back to /data/dbMongoDB was installed with Homebrew, but mongod is run without its configFix
    3. 3the folder exists but mongod still stops at start-up (read the log file)The folder exists but the user running mongod cannot write to itFix

What does the error look like?

  • ERROR: dbpath (/data/db) does not exist.
  • Create this directory or give existing directory in --dbpath.

Cause 1 of 3

You started mongod by hand and the default folder was never created

1Check

The MongoDB docs list /data/db as the default for --dbpath on Linux and macOS. The folder has to exist before the first start.

ls -ld /data/db

2Fix

Create a data folder you own and pass it with --dbpath. A folder in your home directory needs no sudo.

mkdir -p ~/data/db
mongod --dbpath ~/data/db

3Verify

mongod keeps running and mongosh connects.

mongosh --eval 'db.runCommand({ ping: 1 })'

Confirmed by mongodb.com

Did this fix it?

Cause 2 of 3

MongoDB was installed with Homebrew, but mongod is run without its config

1Check

A Homebrew install creates a config file and a data folder (/opt/homebrew on Apple Silicon, /usr/local on Intel). Running a bare mongod ignores both, and the docs say a package install uses a different default for storage.dbPath.

ls /opt/homebrew/etc/mongod.conf /opt/homebrew/var/mongodb

2Fix

Run it as a service, or pass the config file (use /usr/local/etc/mongod.conf on Intel).

brew services start mongodb-community@9.0

# or, in the background with the config file
mongod --config /opt/homebrew/etc/mongod.conf --fork

3Verify

The service shows as started.

brew services list

Confirmed by mongodb.com

Did this fix it?

Cause 3 of 3

The folder exists but the user running mongod cannot write to it

1Check

The account that runs mongod needs read and write access to the data and log folders, as the MongoDB install steps say.

ls -ld ~/data/db

2Fix

Give your user ownership of the folder.

sudo chown "$USER" ~/data/db

3Verify

Start mongod again and check the process.

ps aux | grep -v grep | grep mongod

Confirmed by mongodb.com

Did this fix it?

How do I stop it coming back?

  • Run MongoDB as a service or with a config file, so the data folder is written once and not typed each time.
  • Keep the data folder outside the project folder, so it is not committed or deleted by a clean.
  • For project work, a Docker volume or a managed Atlas cluster avoids host folders altogether.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.