log and the database is stored in /usr/local/var/mongodb . By default there is no access control, anyone can read and write to the database.
The default dbpath for mongodb is /data/db .
MongoDB stores data objects in collections and documents instead of the tables and rows used in traditional relational databases. Collections comprise sets of documents, which are equivalent to tables in a relational database. Documents consist of key-value pairs, which are the basic unit of data in MongoDB.
MongoDB stores data in BSON format both internally, and over the network, but that doesn't mean you can't think of MongoDB as a JSON database. Anything you can represent in JSON can be natively stored in MongoDB, and retrieved just as easily in JSON.
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
}
In the newer version of mongodb v2.6.4 try:
grep dbpath /etc/mongod.conf
It will give you something like this:
dbpath=/var/lib/mongodb
And that is where it stores the data.
While this question is targeted for Linux/Unix instances of Mongo, it's one of the first search results regardless of the operating system used, so for future Windows users that find this:
If MongoDB is set up as a Windows Service in the default manner, you can usually find it by looking at the 'Path to executable' entry in the MongoDB Service's Properties:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With