Tanky Woo
Tanky Woo

Reputation: 5116

About the mongodb's default db path?

Environment:

if I use mongod daemon to start mongodb,the default db path is /data/db

But if I use /etc/init.d/mongodb script to start mongodb, the /etc/conf.d/mongdb write the default db path is /var/lib/mongodb,

I am puzzled that why the db path is not the same?

Upvotes: 0

Views: 915

Answers (1)

Stennie
Stennie

Reputation: 65433

The default dbpath if you start MongoDB without a configuration file is /data/db.

Your init script (/etc/init.d/mongodb) is starting mongodb with the --config (aka -f) option and a path to a config file to use (/etc/conf.d/mongodb).

If you look at the contents of your /etc/config.mongodb configuration file, you should see the dbpath setting with the /var/lib/mongodb directory path that overrides the default. In this case the maintainer of your MongoDB install package has decided that /var/lib is the most appropriate default directory for data files. Generally this is done to be more consistent with the default locations used by other packages in your distribution; the MongoDB data files can live anywhere on your filesystem.

You can also check for any settings that have been overridden by your configuration file in the mongo shell using:

 getCommandLineOpts()

The output will be similar to:

{
    "argv" : [
        "mongod",
        "--dbpath",
        "/var/lib/mongodb"
    ],
    "parsed" : {
        "dbpath" : "/var/lib/mongodb"
    },
    "ok" : 1
}

Upvotes: 4

Related Questions