How to Use the MongoDB mongod Command

This article summarizes the basic main usage and options of the mongod command.

Only the important options are covered here. For many other options, refer to the official manual.

Basic options

Option Description
--config <filename>, -f <filename> Specifies a configuration file that contains startup options.
If the configuration file path contains spaces, enclose it in double quotes (").
The configuration file uses ASCII encoding. Non-ASCII encodings such as UTF-8 are not supported. If both a configuration file and startup options are specified, the startup option values take precedence.
--port <port> Default: 27017
Specifies the port number on which MongoDB waits for TCP connections.
--maxConns <number> Specifies the number of concurrent connections MongoDB allows.
--logpath <path> Specifies the path where the log file is output.
--logappend When MongoDB is restarted, logging continues at the end of the existing log file.
By default, MongoDB backs up the existing log file and creates a new log file when restarted.
--slowms <integer> Default: 100
Specifies the profiling threshold in milliseconds.
--profile <level> Default: 0
Changes the database profiling level.

- 0: Off. Does not perform profiling.
- 1: On. Profiles only slow operations.
- 2: On. Profiles all operations.
--auth Uses database access control.
User configuration changes are performed with the mongo command. If no user exists, only access through localhost is permitted.
--bind_ip <address> Default: all connections
Specifies the IP address where MongoDB accepts connections.
--dbpath <path> Default: C:\data\db
Specifies the storage path where database files are stored.

Windows service installation options

Option Description
--install Adds MongoDB as a Windows service.
If needed, specify --serviceName and --serviceDisplayName at the same time.
--remove Removes the MongoDB service from Windows services.
If a non-default name was installed with --serviceName, specify --serviceName.
--serviceName <name> Default: MongoDB
Specifies the service name.
The name specified here is used as the argument to net start <name> and net stop <name>.
--serviceDisplayName <name> Default: MongoDB
Specifies the name displayed in the service management tool.
--serviceDescription <description> Default: MongoDB Server
Specifies the string displayed in the description of the service management tool. If it contains spaces, enclose it in double quotes (").
--serviceUser <user> Specifies the user that runs MongoDB.
--servicePassword <password> Specifies the password for the user that runs MongoDB.

References