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

前端 未结 12 451
北荒
北荒 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:28

    Found it just by poking around in /var/db. Thanks for the help though--I am sure these answers apply to other systems (e.g. Ubuntu) and will help others!

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

    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
    }
    
    0 讨论(0)
  • 2020-12-12 10:33

    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:

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

    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.

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

    If you could somehow locate mongod.log and the do a grep over it

    grep dbpath mongod.log
    

    The value for dbpath is the data location for mongodb!! All the best :)

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

    From my experience the default location is /var/lib/mongodb after I do

    sudo apt-get install -y mongodb-org
    
    0 讨论(0)
提交回复
热议问题