how to get mongodb's loaded configuration file path

In mongo shell you can run a getCmdLineOpts command on admin database which will give you the command line options used to start the mongod or mongos:

db.runCommand({getCmdLineOpts:1})
{
    "argv" : [
        "/usr/bin/mongod",
        "--config",
        "/etc/mongodb.conf"
    ],
    "parsed" : {
        "config" : "/etc/mongodb.conf",
        "net" : {
            "port" : 27017
        },
        "storage" : {
            "dbPath" : "/var/lib/mongodb"
        },
        "systemLog" : {
            "destination" : "file",
            "logAppend" : true,
            "path" : "/var/log/mongodb/mongodb.log"
        }
    },
    "ok" : 1
}

On ubuntu 16 if you run systemctl status mongodb It will show you the following. At the bottom, you can see --config /etc/mongod.conf, which looks like is the location of my loaded config file

   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2016-08-09 14:33:03 UTC; 3s ago
 Main PID: 6674 (mongod)
    Tasks: 21
   Memory: 40.1M
      CPU: 230ms
   CGroup: /system.slice/mongodb.service
           └─6674 /usr/bin/mongod --quiet --config /etc/mongod.conf

Tags:

Mongodb