mongod stops with: dbpath (/data/db) does not exist
ERROR: 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.
Fix it fast
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 mongodb2Match what you see, then jump to its fix
- 1
dbpath (/data/db) does not existYou started mongod by hand and the default folder was never createdFix - 2
brew list shows mongodb-community, yet mongod falls back to /data/dbMongoDB was installed with Homebrew, but mongod is run without its configFix - 3
the 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
- 1
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/db2Fix
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/db3Verify
mongod keeps running and mongosh connects.
mongosh --eval 'db.runCommand({ ping: 1 })'Confirmed by mongodb.com
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/mongodb2Fix
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 --fork3Verify
The service shows as started.
brew services listConfirmed by mongodb.com
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/db2Fix
Give your user ownership of the folder.
sudo chown "$USER" ~/data/db3Verify
Start mongod again and check the process.
ps aux | grep -v grep | grep mongodConfirmed by mongodb.com
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
Databases
mongod --fork stops with child process failed, exited with error number 1
ERROR: child process failed, exited with error number 1
mongod --fork starts a child that detaches, and the parent only reports that the child died.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
asyncpg InterfaceError: another operation is in progress with SQLAlchemy
InterfaceError raised from a FastAPI endpoint that runs several queries at once
A single database connection can run one operation at a time.
4 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fix