35

I'm using Ubuntu 16.04. I have set up a database MongoDB. When I start it (with mongod command) it says that database is located at /data/db (dbpath=/data/db).

The database works fine. But in files explorer I cannot find that folder. I've looked in Computer folder and in Home (Computer/home/<my name>) folder.

I also showed hidden files and folders with Ctrl+H.

How can I find my database folder?

4 Answers 4

56

You should be able to find the location in the configuration file: /etc/mongod.conf

grep -i dbPath /etc/mongod.conf

According to mongodb docs:

The default path is /data/db directory

By default, MongoDB listens for connections from clients on port 27017, and stores data in the /data/db directory.

If dbPath is set, the mongodb will use the directory specify by dbPath

If you want mongod to store data files at a path other than /data/db you can specify a dbPath. The dbPath must exist before you start mongod. If it does not exist, create the directory and the permissions so that mongod can read and write data to this path. For more information on permissions, see the security operations documentation.

5
  • 2
    I found /etc/mongod.conf (notice there is no 'b' letter). There it says: storage: dbPath: /var/lib/mongodb. And that folder looks like it could be the database. Also the variable is dbPath (uppercase 'P'). But then why the hell when I start mongod it says dbpath=/data/db?
    – croraf
    Dec 3, 2017 at 8:00
  • @croraf - the /data/db is the default value of the path, if dbPath is set, it override this value. Note that in order to use /data/db as actual path, the folder should be exists and have the correct ownership/permissions. see updated answer with link to mongodb docs
    – Yaron
    Dec 3, 2017 at 8:34
  • Thanks! The issue is mongod command outputs "MongoDB starting : pid=2722 port=27017 dbpath=/data/db 64-bit host=korisnik-Lenovo-Y520-15IKBN" indicating that dbpath is /data/db. Although this could be the default path the db starting command should indicate the actual path, in my case /var/lib/mongodb.
    – croraf
    Dec 3, 2017 at 8:38
  • 3
    @croraf /etc/mongod.conf configuration is only used if you Start MongoDB as a service or explicitly pass this on the command line: mongod --config /etc/mongod.conf. If you start mongod without any options the default of /data/db will be used. If you start mongod as a service on Ubuntu, dbPath will be as specified in /etc/mongod.conf (/var/lib/mongodb by default). Typically you want to be managing MongoDB as a service to ensure consistent configuration is used between invocations.
    – Stennie
    Dec 4, 2017 at 3:19
  • 1
    @Stennie Yes it seems mongod is started on OS boot (what you call 'as a service'). This was confusing me. I will check today but probably running mongod gives error that the port is already bound.
    – croraf
    Dec 4, 2017 at 9:20
9

When using linux (Ubuntu), when you install mongodb, it is automatically configured and run by default. The default dbpath is located in mongodb.conf. You should see the following lines:

   # Where to store the data
   dbpath=/var/lib/mongodb

Now, based on mongodb doc:

The default path is[should be] /data/db directory, but if the folder isn't present, mongodb will fire from the path given in the mongodb.conf file.

What to do:

  1. stop your mongodb.
  2. create your default data folder.
  3. restart mongodb: this time it will start from the data folder you created.
0

Try typing file:///data/db/ in the browser (chrome or fire-fox). You'll be able to see the files and collections if you have mongodb installed in system, but all would be encrypted you cannot read them in an editor.

0

That's because the "root" that you are seeing, is not the real root, its the root of your home, on the File explorer, when you are on your 'root' home page, press backspace to go to the parent folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.