File Based Configuration

In addition to accepting Command Line Parameters, MongoDB can also be configured using a configuration file. A configuration file to use can be specified using the -f or --config command line options. On some packaged installs of MongoDB (for example Ubuntu & Debian) the default file can be found in /etc/mongodb.conf which is automatically used when starting and stopping MongoDB from the service.

The following example configuration file demonstrates the syntax to use:

# This is an example config file for MongoDB.
dbpath = /var/lib/mongodb
bind_ip = 127.0.0.1
noauth = true # use 'true' for options that don't take an argument
verbose = true # to disable, comment out.

Parameters

Before 2.0
Unfortunately flag parameters like "quiet" will register as true no matter what value you put after them. So don't write this: "quiet=false", just comment it out, or remove the line.

In 2.0, you can use option=false in the config file and it will be handled correctly (the option will be ignored).

Suppose you were running 1.8 and using a config file with the contents:

auth = false

This would actually enable authentication in 1.8. If you upgrade to 2.0, this would suddenly be parsed correctly, turning off authentication (which you might not want, if you've been running with it on forever). Thus, if you start up with 2.0+ and you have any option=false options in your config file, you'll get a warning that looks like:

warning: remove or comment out this line by starting it with '#', skipping now : auth=false

This is to let you know that this option is being skipped. If you want this option skipped, feel free to ignore this warning.

Basic database configuration

Parameter Meaning Example
dbpath Location of the database files dbpath = /var/lib/mongodb
port Port the mongod will listen on port = 27017
bind_ip
Specific IP address that mongod will listen on
bind_ip = 127.0.0.1
logpath Full filename path to where log messages will be written logpath = /var/log/mongodb/mongodb.log
logappend Whether the log file will be appended to or over-written (default) at start-up logappend = true

Logging

Parameter Meaning Example
cpu Enable periodic logging of CPU utilization and I/O wait cpu = true
verbose Verbose logging output (same as v = true) verbose=true
v[vvvv] Level of verbose logging output vvvvv = true

Security

Parameter Meaning Example
noauth Turn authorization on/off. Off is currently the default noauth = true
auth Turn authorization on/off. Off is currently the default auth = true
keyFile Private key for cluster authentication. keyFile = /var/lib/mongodb/key

Administration & Monitoring

Parameter Meaning Example
nohttpinterface Disable the HTTP interface. The default port is 1000 more than the dbport nohttpinterface = true
rest Turn on simple rest API rest = true
noscripting Turns off server-side scripting. This will result in greatly limited functionality noscripting = true
notablescan Turns off table scans. Any query that would do a table scan fails. notablescan = true
noprealloc Disable data file preallocation. noprealloc = true
nssize Specify .ns file size for new databases in MB nssize = 16
mms-token Account token for Mongo monitoring server. mms-token = mytoken
mms-name Server name for Mongo monitoring server. mms-name = monitor.example.com
mms-interval Ping interval for Mongo monitoring server in seconds. mms-interval = 15
quota Enable quota management quota = true
quotaFiles Determines the number of files per Database (default is 8) quotaFiles = 16

Replication

Parameter Meaning Example
opIdMem Size limit for in-memory storage of op ids in bytes opIdMem = 1000
oplogSize Custom size for replication operation log in MB. oplogSize = 100
Master-slave Replication
Parameter Meaning Example
master In replicated mongo databases, specify here whether this is a slave or master master = true
slave In replicated mongo databases, specify here whether this is a slave or master slave = true
source Specify the source = master.example.com
only Slave only: specify a single database to replicate only = master.example.com
autoresync Automatically resync if slave data is stale autoresync
fastsync Indicate that this instance is starting from a dbpath
snapshot of the repl peer
 
Replica Sets
Parameter Meaning Example
replSet Use replica sets with the specified logical set name.  Typically the optional seed host list need not be specified. replSet = <setname>[/<seedlist>]

Sharding

Parameter Meaning Example
shardsvr Indicates that this mongod will participate in sharding *Optional and just changes the default port shardsvr = true

Journaling

Parameter Meaning Example
journal Whether writes will be journaled or not. This feature enables fast recovery from crashes journal = true
nojournal Turns off journaling if it is enabled by default (1.9.2+) nojournal = true
Notes
  • Lines starting with octothorpes (#) are comments
  • Options are case sensitive
  • The syntax is assignment of a value to an option name
  • All command line options are accepted, for example "vvvv=true"

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus