- Reference >
- MongoDB Package Components >
mongod
mongod¶
Synopsis¶
mongod is the primary daemon process for the MongoDB
system. It handles data requests, manages data format, and performs
background management operations.
This document provides a complete overview of all command line options
for mongod. These options are primarily useful for testing
purposes. In common operation, use the configuration file
options to control the behavior of
your database, which is fully capable of all operations described
below.
Options¶
-
mongod¶
Core Options¶
-
--help,-h¶ Returns a basic help and usage text.
-
--config<filename>,-f<filename>¶ Specifies a configuration file, that you can use to specify runtime-configurations. While the options are equivalent and accessible via the other command line arguments, the configuration file is the preferred method for runtime configuration of mongod. See the Configuration File Options document for more information about these options.
Note
Ensure the configuration file uses ASCII encoding.
mongoddoes not support configuration files with non-ASCII encoding, including UTF-8.
-
--verbose,-v¶ Increases the amount of internal reporting returned on standard output or in the log file specified by
--logpath. Use the-vform to control the level of verbosity by including the option multiple times, (e.g.-vvvvv.)
-
--quiet¶ Runs the
mongodinstance in a quiet mode that attempts to limit the amount of output. This option suppresses:- output from database commands,
including
drop,dropIndexes,diagLogging,validate, andclean. - replication activity.
- connection accepted events.
- connection closed events.
- output from database commands,
including
-
--port<port>¶ Specifies a TCP port for the
mongodto listen for client connections. By defaultmongodlistens for connections on port 27017.UNIX-like systems require root privileges to use ports with numbers lower than 1024.
-
--bind_ip<ip address>¶ The IP address that the
mongodprocess will bind to and listen for connections. By defaultmongodlistens for connections all interfaces. You may attachmongodto any interface; however, when attachingmongodto a publicly accessible interface ensure that you have implemented proper authentication and/or firewall restrictions to protect the integrity of your database.
-
--maxConns<number>¶ Specifies the maximum number of simultaneous connections that
mongodwill accept. This setting will have no effect if it is higher than your operating system’s configured maximum connection tracking threshold.Note
You cannot set
maxConnsto a value higher than 20000.
-
--objcheck¶ Forces the
mongodto validate all requests from clients upon receipt to ensure that clients never insert invalid documents into the database. For objects with a high degree of sub-document nesting,--objcheckcan have a small impact on performance. You can set--noobjcheckto disable object checking at run-time.Changed in version 2.4: MongoDB enables
--objcheckby default, to prevent any client from inserting malformed or invalid BSON into a MongoDB database.
-
--noobjcheck¶ New in version 2.4.
Disables the default document validation that MongoDB performs on all incoming BSON documents.
-
--logpath<path>¶ Specify a path for the log file that will hold all diagnostic logging information.
Unless specified,
mongodwill output all log information to the standard output. Additionally, unless you also specify--logappend, the logfile will be overwritten when the process restarts.Note
The behavior of the logging system may change in the near future in response to the SERVER-4499 case.
-
--logappend¶ When specified, this option ensures that
mongodappends new entries to the end of the logfile rather than overwriting the content of the log when the process restarts.
-
--syslog¶ New in version 2.1.0.
Sends all logging output to the host’s syslog system rather than to standard output or a log file as with
--logpath.
-
--pidfilepath<path>¶ Specify a file location to hold the “PID” or process ID of the
mongodprocess. Useful for tracking themongodprocess in combination with themongod --forkoption.Without a specified
--pidfilepathoption,mongoscreates no PID file.
-
--keyFile<file>¶ Specify the path to a key file to store authentication information. This option is only useful for the connection between replica set members.
See also
-
--nounixsocket¶ Disables listening on the UNIX socket.
mongodalways listens on the UNIX socket, unless--nounixsocketis set,--bind_ipis not set, or--bind_ipdoes not specify127.0.0.1.
-
--unixSocketPrefix<path>¶ Specifies a path for the UNIX socket. Unless this option has a value
mongodcreates a socket with/tmpas a prefix.MongoDB will always create and listen on a UNIX socket, unless
--nounixsocketis set,--bind_ipis not set, or--bind_ipdoes not specify127.0.0.1.
-
--fork¶ Enables a daemon mode for
mongodthat runs the process to the background. This is the normal mode of operation, in production and production-like environments, but may not be desirable for testing.
-
--auth¶ Enables database authentication for users connecting from remote hosts. Configure users via the mongo shell. If no users exist, the localhost interface will continue to have access to the database until you create the first user.
See the Security and Authentication page for more information regarding this functionality.
-
--saslServiceName¶ New in version 2.4.6: Allows users to override the default Kerberos service name component of the Kerberos principal name, on a per-instance basis. If unspecified, the default value is
mongodb.Only settable during start-up. The
setParametercommand does not change this setting.Only available on MongoDB Enterprise.
Important
Ensure that your driver supports alternate service names.
-
--cpu¶ Forces
mongodto report the percentage of CPU time in write lock.mongodgenerates output every four seconds. MongoDB writes this data to standard output or the logfile if using thelogpathoption.
-
--dbpath<path>¶ Specify a directory for the
mongodinstance to store its data. Typical locations include:/srv/mongodb,/var/lib/mongodbor/opt/mongodbUnless specified,
mongodwill look for data files in the default/data/dbdirectory. (Windows systems use the\data\dbdirectory.) If you installed using a package management system. Check the/etc/mongodb.conffile provided by your packages to see the configuration of thedbpath.
-
--diaglog<value>¶ Creates a very verbose, diagnostic log for troubleshooting and recording various errors. MongoDB writes these log files in the
dbpathdirectory in a series of files that begin with the stringdiaglogand end with the initiation time of the logging as a hex string.The specified value configures the level of verbosity. Possible values, and their impact are as follows.
Value Setting 0 off. No logging. 1 Log write operations. 2 Log read operations. 3 Log both read and write operations. 7 Log write and some read operations. You can use the
mongosnifftool to replay this output for investigation. Given a typical diaglog file, located at/data/db/diaglog.4f76a58c, you might use a command in the following form to read these files:--diaglogis for internal use and not intended for most users.Warning
Setting the diagnostic level to
0will causemongodto stop writing data to the diagnostic log file. However, themongodinstance will continue to keep the file open, even if it is no longer writing data to the file. If you want to rename, move, or delete the diagnostic log you must cleanly shut down themongodinstance before doing so.
-
--directoryperdb¶ Alters the storage pattern of the data directory to store each database’s files in a distinct folder. This option will create directories within the
--dbpathnamed for each database.Use this option in conjunction with your file system and device configuration so that MongoDB will store data on a number of distinct disk devices to increase write throughput or disk capacity.
Warning
If you have an existing
mongodinstance anddbpath, and you want to enable--directoryperdb, you must migrate your existing databases to directories before setting--directoryperdbto access those databases.Example
Given a
dbpathdirectory with the following items:To enable
--directoryperdbyou would need to modify thedbpathto resemble the following:
-
--journal¶ Enables operation journaling to ensure write durability and data file validity.
mongodenables journaling by default on 64-bit builds of versions after 2.0.
-
--journalOptions<arguments>¶ Provides functionality for testing. Not for general use, and will affect data file integrity in the case of abnormal system shutdown.
-
--journalCommitInterval<value>¶ Specifies the maximum amount of time for
mongodto allow between journal operations. Possible values are between 2 and 300 milliseconds. Lower values increase the durability of the journal, at the expense of disk performance.The default journal commit interval is 100 milliseconds if a single block device (e.g. physical volume, RAID device, or LVM volume) contains both the journal and the data files.
If the journal is on a different block device than the data files the default journal commit interval is 30 milliseconds.
To force
mongodto commit to the journal more frequently, you can specifyj:true. When a write operation withj:trueis pending,mongodwill reducejournalCommitIntervalto a third of the set value.
-
--ipv6¶ Specify this option to enable IPv6 support. This will allow clients to connect to
mongodusing IPv6 networks.mongoddisables IPv6 support by default inmongodand all utilities.
-
--jsonp¶ Permits JSONP access via an HTTP interface. Consider the security implications of allowing this activity before enabling this option.
-
--noauth¶ Disable authentication. Currently the default. Exists for future compatibility and clarity.
-
--nohttpinterface¶ Disables the HTTP interface.
Note
In MongoDB Enterprise, the HTTP Console does not support Kerberos Authentication.
-
--nojournal¶ Disables the durability journaling. By default,
mongodenables journaling in 64-bit versions after v2.0.
-
--noprealloc¶ Disables the preallocation of data files. This will shorten the start up time in some cases, but can cause significant performance penalties during normal operations.
-
--noscripting¶ Disables the scripting engine.
-
--notablescan¶ Forbids operations that require a table scan.
-
--nssize<value>¶ Specifies the default size for namespace files (i.e
.ns). This option has no impact on the size of existing namespace files. The maximum size is 2047 megabytes.The default value is 16 megabytes; this provides for approximately 24,000 namespaces. Each collection, as well as each index, counts as a namespace.
-
--profile<level>¶ Changes the level of database profiling, which inserts information about operation performance into output of
mongodor the log file. The following levels are available:Level Setting 0 Off. No profiling. 1 On. Only includes slow operations. 2 On. Includes all operations. Profiling is off by default. Database profiling can impact database performance. Enable this option only after careful consideration.
-
--quota¶ Enables a maximum limit for the number data files each database can have. When running with
--quota, there are a maximum of 8 data files per database. Adjust the quota with the--quotaFilesoption.
-
--quotaFiles<number>¶ Modify limit on the number of data files per database. This option requires the
--quotasetting. The default value for--quotaFilesis 8.
-
--repair¶ Runs a repair routine on all databases. This is equivalent to shutting down and running the
repairDatabasedatabase command on all databases.Warning
During normal operations, only use the
repairDatabasecommand and wrappers includingdb.repairDatabase()in themongoshell andmongod --repair, to compact database files and/or reclaim disk space. Be aware that these operations remove and do not save any corrupt data during the repair process.If you are trying to repair a replica set member, and you have access to an intact copy of your data (e.g. a recent backup or an intact member of the replica set), you should restore from that intact copy, and not use
repairDatabase.Note
When using journaling, there is almost never any need to run
repairDatabase. In the event of an unclean shutdown, the server will be able restore the data files to a pristine state automatically.Changed in version 2.1.2.
If you run the repair option and have data in a journal file,
mongodrefuses to start. In these cases you should startmongodwithout the--repairoption to allowmongodto recover data from the journal. This completes more quickly and is more likely to produce valid data files.To continue the repair operation despite the journal files, shut down
mongodcleanly and restart with the--repairoption.Note
--repaircopies data from the source data files into new data files in therepairpath, and then replaces the original data files with the repaired data files. Ifrepairpathis on the same device asdbpath, you may interrupt amongodrunning--repairwithout affecting the integrity of the data set.
-
--repairpath<path>¶ Specifies the root directory containing MongoDB data files, to use for the
--repairoperation. Defaults to a_tmpdirectory within thedbpath.
-
--setParameter<options>¶ New in version 2.4.
Specifies an option to configure on startup. Specify multiple options with multiple
--setParameteroptions. See mongod Parameters for full documentation of these parameters. ThesetParameterdatabase command provides access to many of these parameters.--setParametersupports the following options:
-
--slowms<value>¶ Defines the value of “slow,” for the
--profileoption. The database logs all slow queries to the log, even when the profiler is not turned on. When the database profiler is on,mongodthe profiler writes to thesystem.profilecollection. See theprofilecommand for more information on the database profiler.
-
--smallfiles¶ Enables a mode where MongoDB uses a smaller default file size. Specifically,
--smallfilesreduces the initial size for data files and limits them to 512 megabytes.--smallfilesalso reduces the size of each journal files from 1 gigabyte to 128 megabytes.Use
--smallfilesif you have a large number of databases that each holds a small quantity of data.--smallfilescan lead yourmongodto create a large number of files, which may affect performance for larger databases.
-
--shutdown¶ Used in control scripts, the
--shutdownwill cleanly and safely terminate themongodprocess. When invokingmongodwith this option you must set the--dbpathoption either directly or by way of the configuration file and the--configoption.The
--shutdownoption is available only on Linux systems.
-
--syncdelay<value>¶ mongodwrites data very quickly to the journal, and lazily to the data files.--syncdelaycontrols how much time can pass before MongoDB flushes data to the database files via an fsync operation. The default setting is 60 seconds. In almost every situation you should not set this value and use the default setting.The
serverStatuscommand reports the background flush thread’s status via thebackgroundFlushingfield.syncdelayhas no effect on thejournalfiles or journaling.Warning
If you set
--syncdelayto0, MongoDB will not sync the memory mapped files to disk. Do not set this value on production systems.
-
--sysinfo¶ Returns diagnostic system information and then exits. The information provides the page size, the number of physical pages, and the number of available physical pages.
-
--upgrade¶ Upgrades the on-disk data format of the files specified by the
--dbpathto the latest version, if needed.This option only affects the operation of
mongodif the data files are in an old format.Note
In most cases you should not set this value, so you can exercise the most control over your upgrade process. See the MongoDB release notes (on the download page) for more information about the upgrade process.
-
--traceExceptions¶ For internal diagnostic use only.
Replication Options¶
-
--replSet<setname>¶ Use this option to configure replication with replica sets. Specify a replica set name as an argument to this set. All hosts in the replica set must have the same set name.
Important
If your application connects to more than one replica set, each set should have a distinct name. Some drivers group replica set connections by replica set name.
See also
Replication, Replica Set Tutorials, and Replica Set Configuration
-
--oplogSize<value>¶ Specifies a maximum size in megabytes for the replication operation log (e.g. oplog.) By
mongodcreates an oplog based on the maximum amount of space available. For 64-bit systems, the op log is typically 5% of available disk space.Once the
mongodhas created the oplog for the first time, changing--oplogSizewill not affect the size of the oplog.
-
--fastsync¶ In the context of replica set replication, set this option if you have seeded this member with a snapshot of the dbpath of another member of the set. Otherwise the
mongodwill attempt to perform an initial sync, as though the member were a new member.
-
--replIndexPrefetch¶ New in version 2.2.
You must use
--replIndexPrefetchin conjunction withreplSet. The default value isalland available options are:noneall_id_only
By default secondary members of a replica set will load all indexes related to an operation into memory before applying operations from the oplog. You can modify this behavior so that the secondaries will only load the
_idindex. Specify_id_onlyornoneto prevent themongodfrom loading any index into memory.
Master-Slave Replication¶
These options provide access to conventional master-slave database replication. While this functionality remains accessible in MongoDB, replica sets are the preferred configuration for database replication.
-
--source<host><:port>¶ For use with the
--slaveoption, the--sourceoption designates the server that this instance will replicate.
-
--only<arg>¶ For use with the
--slaveoption, the--onlyoption specifies only a single database to replicate.
-
--slavedelay<value>¶ For use with the
--slaveoption, the--slavedelayoption configures a “delay” in seconds, for this slave to wait to apply operations from the master node.
-
--autoresync¶ For use with the
--slaveoption. When set,--autoresyncoption allows this slave to automatically resync if it is more than 10 seconds behind the master. This setting may be problematic if the--oplogSizespecifies a too small oplog. If the oplog is not large enough to store the difference in changes between the master’s current state and the state of the slave, this instance will forcibly resync itself unnecessarily. When you set theautoresyncoption tofalse, the slave will not attempt an automatic resync more than once in a ten minute period.
Sharding Cluster Options¶
-
--configsvr¶ Declares that this
mongodinstance serves as the config database of a sharded cluster. When running with this option, clients will not be able to write data to any database other thanconfigandadmin. The default port for amongodwith this option is27019and the default--dbpathdirectory is/data/configdb, unless specified.Changed in version 2.2:
--configsvralso sets--smallfiles.Changed in version 2.4:
--configsvrcreates a local oplog.Do not use
--configsvrwith--replSetor--shardsvr. Config servers cannot be a shard server or part of a replica set.
-
--shardsvr¶ Configures this
mongodinstance as a shard in a partitioned cluster. The default port for these instances is27018. The only effect of--shardsvris to change the port number.
-
--moveParanoia¶ New in version 2.4: MongoDB 2.4 does not specify
--moveParanoiaby default.During chunk migrations,
--moveParanoiaforces themongodinstances to save all documents migrated from this shard in themoveChunkdirectory of thedbpath. MongoDB does not delete data from this directory.Prior to 2.4,
--moveParanoiabehavior was the default behavior of MongoDB.
SSL Options¶
See
Connect to MongoDB with SSL for full documentation of MongoDB’s support.
-
--sslOnNormalPorts¶ New in version 2.2.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Enables SSL for
mongod. With--sslOnNormalPorts, amongodrequires SSL encryption for all connections on the default MongoDB port, or the port specified by--port. By default,--sslOnNormalPortsis disabled.
-
--sslPEMKeyFile<filename>¶ New in version 2.2.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Specifies the
.pemfile that contains both the SSL certificate and key. Specify the file name of the.pemfile using relative or absolute pathsWhen using
--sslOnNormalPorts, you must specify--sslPEMKeyFile.
-
--sslPEMKeyPassword<value>¶ New in version 2.2.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Specifies the password to de-crypt the certificate-key file (i.e.
--sslPEMKeyFile). Only use--sslPEMKeyPasswordif the certificate-key file is encrypted. In all cases,mongodwill redact the password from all logging and reporting output.Changed in version 2.4:
--sslPEMKeyPasswordis only needed when the private key is encrypted. In earlier versionsmongodwould require--sslPEMKeyPasswordwhenever using--sslOnNormalPorts, even when the private key was not encrypted.
-
--sslCAFile<filename>¶ New in version 2.4.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Specifies the
.pemfile that contains the root certificate chain from the Certificate Authority. Specify the file name of the.pemfile using relative or absolute paths
-
--sslCRLFile<filename>¶ New in version 2.4.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Specifies the
.pemfile that contains the Certificate Revocation List. Specify the file name of the.pemfile using relative or absolute paths
-
--sslWeakCertificateValidation¶ New in version 2.4.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
Disables the requirement for SSL certificate validation, that
--sslCAFileenables. With--sslWeakCertificateValidation,mongodwill accept connections if the client does not present a certificate when establishing the connection.If the client presents a certificate and
mongodhas--sslWeakCertificateValidationenabled,mongodwill validate the certificate using the root certificate chain specified by--sslCAFile, and reject clients with invalid certificates.Use
--sslWeakCertificateValidationif you have a mixed deployment that includes clients that do not or cannot present certificates tomongod.
-
--sslFIPSMode¶ New in version 2.4.
Note
The default distribution of MongoDB does not contain support for SSL. To use SSL you can either compile MongoDB with SSL support or use MongoDB Enterprise. See Connect to MongoDB with SSL for more information about SSL and MongoDB.
When specified,
mongodwill use the FIPS mode of the installed OpenSSL library. Your system must have a FIPS compliant OpenSSL library to use--sslFIPSMode.
Usage¶
In common usage, the invocation of mongod will resemble the
following in the context of an initialization or control script:
See the Configuration File Options for more information
on how to configure mongod using the configuration file.