How do I specify mongodb's config file?

Solution 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:

/etc/init/mongodb.conf

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]

script
  ENABLE_MONGODB="yes"
  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.