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

前端 未结 12 450
北荒
北荒 2020-12-12 10:03

My host came with a mongodb instance and there is no /db directory so now I am wondering what I can do to find out where the data is actually being stored.

相关标签:
12条回答
  • 2020-12-12 10:17

    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.

    0 讨论(0)
  • 2020-12-12 10:19

    I found mine here on a OSX system /usr/local/var/mongodb

    0 讨论(0)
  • 2020-12-12 10:22

    When you start it up it shows you. But I don't know if it is something you can do or not on your host. If you have access to the command line and can restart the service, you will get something like:

        2016-11-15T12:57:09.182-0500 I CONTROL  [initandlisten]
     MongoDB starting : pid=16448 port=27017 dbpath=C:\data\db\ 
    
    0 讨论(0)
  • 2020-12-12 10:23

    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...

    0 讨论(0)
  • 2020-12-12 10:25

    For windows Go inside MongoDB\Server\4.0\bin folder and open mongod.cfg file in any text editor. Then locate the line that specifies the dbPath param. The line looks something similar

    dbPath: D:\Program Files\MongoDB\Server\4.0\data

    0 讨论(0)
  • 2020-12-12 10:27

    Actually, the default directory where the mongod instance stores its data is

    /data/db on Linux and OS X,

    \data\db on Windows

    To check the same, you can look for dbPath settings in mongodb configuration file.

    • On Linux, the location is /etc/mongod.conf, if you have used package manager to install MongoDB. Run the following command to check the specified directory:
      grep dbpath /etc/mongodb.conf
      
    • On Windows, the location is <install directory>/bin/mongod.cfg. Open mongod.cfg file and check for dbPath option.
    • On macOS, the location is /usr/local/etc/mongod.conf when installing from MongoDB’s official Homebrew tap.

    The default mongod.conf configuration file included with package manager installations uses the following platform-specific default values for storage.dbPath:

    +--------------------------+-----------------+------------------------+
    |         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 |
    +--------------------------+-----------------+------------------------+
    

    The storage.dbPath setting in the configuration file is available only for mongod.

    The Linux package init scripts do not expect storage.dbPath to change from the defaults. If you use the Linux packages and change storage.dbPath, you will have to use your own init scripts and disable the built-in scripts.

    Source

    0 讨论(0)
提交回复
热议问题