I got an error about dbpath (/data/db/) does not exist
, but /etc/mongodb.conf
named it dbpath = /var/lib/mongodb.
So, which is the de
The default dbpath for mongodb is /data/db
.
There is no default config file, so you will either need to specify this when starting mongod
with:
mongod --config /etc/mongodb.conf
.. or use a packaged install of MongoDB (such as for Redhat or Debian/Ubuntu) which will include a config file path in the service definition.
Note: to check the dbpath and command-line options for a running mongod
, connect via the mongo
shell and run:
db.serverCmdLineOpts()
In particular, if a custom dbpath
is set it will be the value of:
db.serverCmdLineOpts().parsed.dbpath // MongoDB 2.4 and older
db.serverCmdLineOpts().parsed.storage.dbPath // MongoDB 2.6+
The Windows x64 installer shows the a path in the installer UI/wizard.
You can confirm which path it used later, by opening your mongod.cfg
file. My mongod.cfg
was located here C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
(change for your version of MongoDB!
When I opened my mongd.cfg
I found this line, showing the default db path:
dbPath: C:\Program Files\MongoDB\Server\4.0\data
However, this caused an error when trying to run mongod
, which was still expecting to find C:\data\db
:
2019-05-05T09:32:36.084-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
You could pass mongod
a --dbpath=...
parameter. In my case:
mongod --dbpath="C:\Program Files\MongoDB\Server\4.0\data"
I have version 2.0.7 installed on Ubuntu and it defaulted to /var/lib/mongodb/
and that is also what was placed into my /etc/mongodb.conf
file.
I depends on the version and the distro.
For example the default download pre-2.2 from the MongoDB site uses: /data/db
but the Ubuntu install at one point used to use: var/lib/mongodb
.
I think these have been standardised now so that 2.2+ will only use data/db
whether it comes from direct download on the site or from the repos.
For a Windows machine start the mongod
process by specifying the dbpath:
mongod --dbpath \mongodb\data
Reference: Manage mongod Processes