I tried mongod --dbpath=/data option to change the data directory location, by executing this command continously running in forground waiting for connection

it works on mongo CLI, But after I stop the mongod --dbpath=/data by CTRL +C, mongo CLI refuse to Connect

Then After restarting mongod service, it's just normally use by default path in root directory.

Then I edited in /etc/mongodb.conf db path parameter, after mongob serive can't start

Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: 
   Active: failed (Result: exit-code) since Mon 2019-07-15 19:36:47 IST; 5s ago
     Docs: https://docs.mongodb.org/manual
  Process: 5355 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited
 Main PID: 5355 (code=exited, status=2)

How do I make this permanent

**I change that new directory ownership to mongodb user **I am using Ubuntu

  • 1
    Changing the dbPath in your configuration path (/etc/mongod.conf according to your service message would be the right place to persist the change. If you review the MongoDB log file (as per systemLog.path in the config file), there should be more context on the startup error. I would check that directory and file permissions are correct for the dbPath and log path. If you are still having issues, please edit your question to include details of the startup error from the MongoDB server log.
    – Stennie
    Jul 16, 2019 at 3:13

2 Answers 2


Finally fixed that problem, I am actually put small case P in dbPath option. Then I properly give ownership that directory to mongodb user account, It works perfect!


change your init.d/mongodb script and make the following changes.I have used my own config ie. mongod1.conf. Make sure to change the ownership of the dbpath and log to mongodb

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .