'What is the default database path for MongoDB?
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 default dbpath for MongoDB?
Solution 1:[1]
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+
Solution 2:[2]
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.
Solution 3:[3]
For a Windows machine start the mongod process by specifying the dbpath:
mongod --dbpath \mongodb\data
Reference: Manage mongod Processes
Solution 4:[4]
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.
Solution 5:[5]
The dbPath in Mongo can be confusing. If you don't specify the dbPath at all (neither as command line parameter nor in mongod.conf file) then it defaults to
/data/dbon Linux and macOS\data\dbon Windows (on current drive)
However, the default mongod.conf files which comes along the installation uses these ones:
| Platform | Package Manager | Default storage.dbPath |
|---|---|---|
| RHEL / CentOS and Amazon | yum | /var/lib/mongo |
| SUSE | zypper | /var/lib/mongo |
| Ubuntu and Debian | apt | /var/lib/mongodb |
| macOS | brew | /usr/local/var/mongodb |
| Windows | MSI | C:\Program Files\MongoDB\Server\{release}\data\ |
So, you must carefully check what you are using.
Solution 6:[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"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | HeatfanJohn |
| Solution 3 | Peter Mortensen |
| Solution 4 | Sammaye |
| Solution 5 | |
| Solution 6 |
