I am running mongodb as a service on ubuntu server. How can I specify the config file that mongoDB uses?

Is there a file with the command that starts mongod that I can edit to add the --config flag?

  • Have you tried the mongodb.conf file?
    – Mitch
    Dec 19, 2013 at 6:48
  • @Mitch Yeah, it isn't using it. I'm trying to make it use it. Dec 19, 2013 at 23:25

1 Answer 1


You say you are running MongoDB as a service, so I am going to assume that you followed the instructions here to install the service and that you are starting and stopping the service using Upstart: sudo service mongodb start and sudo service mongodb stop.

If this is the case, then the Upstart job that is controlling your service will be here:


Let's take a look at the contents (note: you will need root permissions to edit the file):

# Ubuntu upstart file at /etc/init/mongodb.conf

limit nofile 20000 20000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

pre-start script
    mkdir -p /var/lib/mongodb/
    mkdir -p /var/log/mongodb/
end script

start on runlevel [2345]
stop on runlevel [06]

  if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
  if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script

The piece that pertains to your question is the second line from the bottom. That is the one that specifies the config file to use. Here is just the relevant snippet:

/usr/bin/mongod -- --config /etc/mongodb.conf

As you can see, the config file is already being specified, so all you need to do to make config changes to your MongoDB service is edit that file at /etc/mongodb.conf.

After changing your config, you will need to restart the service: sudo service mongodb restart.

  • 1
    I guess it's a problem with mongodb because I already tried that and it didn't work. Dec 19, 2013 at 23:34
  • 1
    I think it's more likely that there is something more basic we are missing here - I very much doubt that such a basic problem (reading from a config file) would have gone unnoticed in MongoDB or that you would be the only one to see the issue. I just tested changing some of the values and it worked for me on Ubuntu 12.04. Once you change the values in the config file, you have to restart the service for them to take effect, and of course, they have to be valid changes.
    – Adam C
    Dec 20, 2013 at 0:59
  • I tried other config options after posting that comment, and they worked, but the one I was trying to change, auth, was not having any effect. I got it working now. Dec 20, 2013 at 22:26

You must log in to answer this question.

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