- Reference >
- MongoDB Server Parameters
MongoDB Server Parameters¶
Synopsis¶
MongoDB provides a number of configuration options that are accessible via the --setParameter option to mongod. This document documents all of these options.
For additional run time configuration options, see Configuration File Options and Manual Page for mongod.
Parameters¶
- enableLocalhostAuthBypass¶
2.4 新版功能.
Specify 0 to disable localhost authentication bypass. Enabled by default.
enableLocalhostAuthBypass is not available using setParameter database command. Use the setParameter option in the configuration file or the --setParameter option on the command line.
- enableTestCommands¶
2.4 新版功能.
enableTestCommands enables a set of internal commands useful for internal testing operations. enableTestCommands is only available when starting mongod and you cannot use setParameter to modify this parameter. Consider the following mongod invocation, which sets enableTestCommands:
mongod --setParameter enableTestCommands=1
enableTestCommands provides access to the following internal commands:
- journalCommitInterval¶
Specify an integer between 1 and 500 signifying the number of milliseconds (ms) between journal commits.
Consider the following example which sets the journalCommitInterval to 200 ms:
db.getSiblingDB("admin").runCommand( { setParameter: 1, journalCommitInterval: 200 } )
参见
- logUserIds¶
2.4 新版功能.
Specify 1 to enable logging of userids.
Disabled by default.
- logLevel¶
Specify an integer between 0 and 5 signifying the verbosity of the logging, where 5 is the most verbose.
Consider the following example which sets the logLevel to 2:
use admin db.runCommand( { setParameter: 1, logLevel: 2 } )
参见
- notablescan¶
Specify whether all queries must use indexes. If 1, MongoDB will not execute queries that require a table scan and will return an error.
Consider the following example which sets notablescan to 1 or true:
db.getSiblingDB("admin").runCommand( { setParameter: 1, notablescan: 1 } )
Setting notablescan to 1 can be useful for testing application queries, for example, to identify queries that scan an entire collection and cannot use an index.
To detect unindexed queries without notablescan, consider reading the Evaluate Performance of Current Operations and Optimize Query Performance sections and using the logLevel parameter, mongostat and profiling.
Don’t run production mongod instances with notablescan because preventing table scans can potentially affect queries in all databases, including administrative queries.
- replIndexPrefetch¶
2.2 新版功能.
Use replIndexPrefetch in conjunction with replSetName when configuring a replica set. The default value is all and available options are:
- none
- all
- _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 _id index. Specify _id_only or none to prevent the mongod from loading any index into memory.
- replApplyBatchSize¶
1.6 新版功能.
Specify the number of oplog entries to apply as a single batch. replApplyBatchSize must be an integer between 1 and 1024. The default value is 1. This option only applies to master/slave configurations and is valid only on a mongod started with the --slave command line option.
Batch sizes must be 1 for members with slavedelay configured.
- saslHostName¶
2.4 新版功能.
saslHostName overrides MongoDB’s default hostname detection for the purpose of configuring SASL and Kerberos authentication.
saslHostName does not affect the hostname of the mongod or mongos instance for any purpose beyond the configuration of SASL and Kerberos.
You can only set saslHostName during start-up, and cannot change this setting using the setParameter database command.
注解
saslHostName supports Kerberos authentication and is only included in MongoDB Enterprise. For Linux systems, see Configure MongoDB with Kerberos Authentication on Linux for more information.
- supportCompatibilityFormPrivilegeDocuments¶
2.4 新版功能.
2.6 版后已移除: supportCompatibilityFormPrivilegeDocuments has no effect in 2.6 and will be removed in 2.8.
supportCompatibilityFormPrivilegeDocuments is not available using setParameter database command. Use the setParameter option in the configuration file or the --setParameter option on the command line.
- syncdelay¶
Specify the interval in seconds between fsync operations where mongod flushes its working memory to disk. By default, mongod flushes memory to disk every 60 seconds. In almost every situation you should not set this value and use the default setting.
Consider the following example which sets the syncdelay to 60 seconds:
db.getSiblingDB("admin").runCommand( { setParameter: 1, syncdelay: 60 } )
参见
syncPeriodSecs and journalCommitInterval.
- traceExceptions¶
2.2 新版功能.
Configures mongod log full stack traces on assertions or errors. If 1, mongod will log full stack traces on assertions or errors.
Consider the following example which sets the traceExceptions to true:
db.getSiblingDB("admin").runCommand( { setParameter: 1, traceExceptions: true } )
- quiet¶
Sets quiet logging mode. If 1, mongod will go into a quiet logging mode which will not log the following events/activities:
- connection events;
- the drop command, the dropIndexes command, the diagLogging command, the validate command, and the clean command; and
- replication synchronization activities.
Consider the following example which sets the quiet to 1:
db = db.getSiblingDB("admin") db.runCommand( { setParameter: 1, quiet: 1 } )
参见
- textSearchEnabled¶
2.6 版后已移除: MongoDB enables the text search feature by default. Manual enabling of this feature is unnecessary.
Enables the text search feature. When manually enabling, you must enable on each and every mongod for replica sets.
- releaseConnectionsAfterResponse¶
2.2.4 新版功能: and 2.4.2
Changes the behavior of the connection pool that mongos uses to connect to the shards. As a result, each mongos should need to maintain fewer connections to each shard. When enabled, the mongos will release a connection into the thread pool after each read operation or command.
警告
For applications that do not use the default, journaled, or replica acknowledged write concern modes of the driver, releaseConnectionsAfterResponse will affect the meaning of getLastError.
If an application allows read operations in between write operations and getLastError calls, the resulting getLastError will not report on the success of the proceeding write operation.
Use with caution.
To enable, use the following command while connected to a mongos:
db.getSiblingDB('admin').runCommand( { setParameter: 1, releaseConnectionsAfterResponse: true } )
Alternately, you may start the mongos instance with the following run-time option:
mongos --setParameter releaseConnectionsAfterResponse=true
To change this policy for the entire cluster, you must set releaseConnectionsAfterResponse on each mongos instance in the cluster.
- connPoolMaxShardedConnectionsPerHost¶
2.6 新版功能.
Default: 200
mongos instances reuse connections to the shards to service multiple requests. However, in some situations very active mongos instances may need to maintain a pool larger than the default maximum of 200 connections.
The connPoolMaxShardedConnectionsPerHost value defines the size of the largest connection pool that mongos instances will maintain for communication to the shards. The size of a pool does not prevent mongos instances from creating additional connections, but does prevent the connection pools from retaining connections above this limit.
Increase the connPoolMaxShardedConnectionsPerHost value only if the number of connections in a connection pool has a high level of churn, or if the total number of created connections increase.
connPoolMaxShardedConnectionsPerHost only applies for mongos instances. You can only set connPoolMaxShardedConnectionsPerHost during start up in the config file or on the command line, as follows to increase the size of the connection pool:
mongos --setParameter connPoolMaxShardedConnectionsPerHost=250
- connPoolMaxConnectionsPerHost¶
2.6 新版功能.
Default: 200
mongod maintains connection pools for outgoing connections to other mongod instances to maximize connection reuse.
The connPoolMaxConnectionsPerHost value defines the size of the largest connection pool that mongod instances will maintain for inter-process communication. The size of a pool does not prevent a mongod from creating additional connections, but does prevent a connection pool from retaining connections in excess of the value of connPoolMaxConnectionsPerHost.
Only adjust this setting if your driver does not pool connections and you’re using authentication in the context of a sharded cluster.
connPoolMaxShardedConnectionsPerHost applies to mongod instances only. You can only set connPoolMaxShardedConnectionsPerHost during start up in the config file or on the command line, as follows to increase the size of the connection pool:
mongos --setParameter connPoolMaxConnectionsPerHost=250
- authenticationMechanisms¶
在 2.6 版更改: Added support for the PLAIN and MONGODB-X509 authentication mechanisms.
Specifies the list of authentication mechanisms the server accepts. Set this to one or more of the following values. If you specify multiple values, use a comma-separated list and no spaces. For descriptions of the authentication mechanisms, see 认证.
Value Description MONGODB-CR MongoDB challenge/response authentication. MONGODB-X509 MongoDB SSL certificate authentication. PLAIN External authentication using LDAP. You can also use PLAIN for authenticating in-database users. PLAIN transmits passwords in plain text. This mechanism is available only in MongoDB Enterprise. GSSAPI External authentication using Kerberos. This mechanism is available only in MongoDB Enterprise. For example, to specify PLAIN as the authentication mechanism, use the following command:
mongod --setParameter authenticationMechanisms=PLAIN --auth
- saslauthdPath¶
注解
Available only in MongoDB Enterprise (except MongoDB Enterprise for Windows).
Specify the path to the Unix Domain Socket of the saslauthd instance to use for proxy authentication.
- sslMode¶
2.6 新版功能.
Set the net.ssl.mode to either preferSSL or requireSSL. Useful during rolling upgrade to SSL to minimize downtime.
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 Configure mongod and mongos for SSL for more information about SSL and MongoDB.
db.getSiblingDB('admin').runCommand( { setParameter: 1, sslMode: "preferSSL" } )
- clusterAuthMode¶
2.6 新版功能.
Set the clusterAuthMode to either sendX509 or x509. Useful during rolling upgrade to use x509 for membership authentication to minimize downtime.
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 Configure mongod and mongos for SSL for more information about SSL and MongoDB.
db.getSiblingDB('admin').runCommand( { setParameter: 1, clusterAuthMode: "sendX509" } )
- ttlMonitorEnabled¶
2.4.6 新版功能.
To support TTL Indexes, mongod instances have a background thread that is responsible for deleting documents from collections with TTL indexes.
To disable this worker thread for a mongod, set ttlMonitorEnabled to false, as in the following operations:
db.getSiblingDB('admin').runCommand( { setParameter: 1, ttlMonitorEnabled: false } )
Alternately, you may disable the thread at run-time by starting the mongod instance with the following option:
mongod --setParameter ttlMonitorEnabled=false
- saslServiceName¶
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.
MongoDB only permits setting saslServiceName at startup. The setParameter command can not change this setting.
saslServiceName is only available in MongoDB Enterprise.
重要
Ensure that your driver supports alternate service names.
- newCollectionsUsePowerOf2Sizes¶
2.6 新版功能.
Default: true.
mongod uses an allocation strategy called usePowerOf2Sizes where each record has a size, in bytes that is a power of 2 (e.g. 32, 64, 128, 256, 512...16777216.) The minimum allocation for a document is 32 bytes.
MongoDB stores documents in contiguous spaces on disk, and each record includes both the document itself and some additional space to allow the document to grow slightly through updates.
By default, all new collections, created after 2.6 use the usePowerOf2Sizes strategy. To revert to the prior exact fit allocation strategy, set newCollectionsUsePowerOf2Sizes to false.
New collections include those: created during initial sync, as well as those created by the mongorestore and mongoimport tools, by running mongod with the --repair option, as well as the restoreDatabase command.
Issue the following command to change the allocation strategy for a running mongod instance:
db.getSiblingDB('admin').runCommand( { setParameter: 1, newCollectionsUsePowerOf2Sizes: false } )
You can also set newCollectionsUsePowerOf2Sizes at run-time with the following operation.
mongod --setParameter newCollectionsUsePowerOf2Sizes=false
- userCacheInvalidationIntervalSecs¶
2.6 新版功能.
Default: 600.
On a mongos instance, this specifies the amount of time in seconds to allow before the mongos instance purges the in-memory cache of user objects. The cache includes the users’ credentials and roles.
This parameter has a minimum value of 30 seconds and a maximum value of 86400 seconds (24 hours).
- failIndexKeyTooLong¶
2.6 新版功能.
In MongoDB 2.6, if you attempt to insert or update a document so that the value of an indexed field is longer than the Index Key Length Limit, the operation will fail and return an error to the client. In previous versions of MongoDB, these operations would successfully insert or modify a document but the index or indexes would not include references to the document.
To avoid this issue, consider using hashed indexes or indexing a computed value. If you have an existing data set and want to disable this behavior so you can upgrade and then gradually resolve these indexing issues, you can use:parameter:failIndexKeyTooLong to disable this behavior.
failIndexKeyTooLong defaults to true. When false, a 2.6 mongod instance will provide the 2.4 behavior.
Issue the following command to disable the index key length validation: for a running:program:mongod instance:
db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )
You can also set failIndexKeyTooLong at run-time with the following operation.
mongod --setParameter failIndexKeyTooLong=false