How can I tell where mongoDB is storing data? (its not in the default /data/db!) How can I tell where mongoDB is storing data? (its not in the default /data/db!) database database

How can I tell where mongoDB is storing data? (its not in the default /data/db!)


mongod defaults the database location to /data/db/.

If you run ps -xa | grep mongod and you don't see a --dbpath which explicitly tells mongod to look at that parameter for the db location and you don't have a dbpath in your mongodb.conf, then the default location will be: /data/db/ and you should look there.


What does your configuration file say?

$ grep dbpath /etc/mongodb.conf

If it is not correct, try this, your database files will be present on the list:

$ sudo lsof -p `ps aux | grep mongodb | head -n1 | tr -s ' ' | cut -d' ' -f 2` | grep REG

It's /var/lib/mongodb/* on my default installation (Ubuntu 11.04).

Note that there is also a /var/lib/mongodb/mongod.lock file holding mongod PID for convenience, however it is located in the data directory - which we are looking for...


I find db.serverCmdLineOpts() the most robust way to find actual path if you can connect to the server. The "parsed.storage.dbPath" contains the path your server is currently using and is available both when it's taken from the config or from the command line arguments.

Also in my case it was important to make sure that the config value reflects the actual value (i.e. config didn't change after the last restart), which isn't guaranteed by the solutions offered here.

db.serverCmdLineOpts()

Example output:

{    "argv" : [         // --    ],    "parsed" : {        "config" : "/your-config",        "storage" : {            "dbPath" : "/your/actual/db/path",            // --        }    },    "ok" : 1.0}