Connection String Options连接字符串选项
This page lists all connection options to connect to your database using SRV connection strings and standard connection strings.此页面列出了使用SRV连接字符串和标准连接字符串连接到数据库的所有连接选项。
Connection options are pairs in the following form: name=value.连接选项按以下形式成对:name=value。
The option name is case insensitive when using a driver.使用驱动程序时,选项name不区分大小写。
The option name is case insensitive when using mongosh.使用mongosh时,选项name不区分大小写。
The value is always case sensitive.value始终区分大小写。
Separate options with the ampersand (&) character name1=value1&name2=value2. In the following example, a connection includes the replicaSet and connectTimeoutMS options:用与号(&)字符name1=value1&name2=value2分隔选项。在以下示例中,连接包括replicaSet和connectTimeoutMS选项:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db1.example.net:27017,db2.example.net:2500/?replicaSet=test&connectTimeoutMS=300000
Note
Semi-colon separator for connection string arguments连接字符串参数的分号分隔符
To provide backwards compatibility, drivers currently accept semi-colons (;) as option separators.为了提供向后兼容性,驱动程序目前接受分号(;)作为选项分隔符。
Replica Set Option副本集选项
The following connection string connects to a replica set named myRepl with members running on the specified hosts. 以下连接字符串连接到名为myRepl的副本集,其成员在指定主机上运行。It authenticates as user myDatabaseUser with the password D1fficultP%40ssw0rd:它以用户myDatabaseUser身份进行身份验证,密码为D1fficultP%40ssw0rd:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com:27017,db1.example.com:27017,db2.example.com:27017/?replicaSet=myRepl
Connection Option连接选项 | Description描述 |
replicaSet | Specifies the name of the replica set, if the mongod is a member of a replica set. Set the replicaSet connection option to ensure consistent behavior across drivers.如果mongod是副本集的成员,则指定副本集的名称。设置replicaSet连接选项,以确保驱动程序之间的行为一致。
When connecting to a replica set, provide a seed list of the replica set member(s) to the host[:port] component of the uri. For specific details, refer to your driver documentation.连接到副本集时,向uri的host[:port]组件提供副本集成员的种子列表。有关具体详细信息,请参阅您的驱动程序文档。
|
directConnection | Specifies whether the client connects directly to the host[:port] in the connection URI:指定客户端是否直接连接到连接URI中的host[:port]:
true: The client sends operations to only the specified host. It doesn't attempt to discover any other members of the replica set.:客户端仅向指定的主机发送操作。它不会尝试发现副本集的任何其他成员。
false: The client attempts to discover all servers in the replica set, and sends operations to the primary member. This is the default value.:客户端尝试发现副本集中的所有服务器,并将操作发送给主要成员。这是默认值。
IMPORTANT:重要: When a replica set runs in Docker, it might expose only one MongoDB endpoint. In this case, the replica set is not discoverable, and specifying directConnection=false can prevent your application from connecting to it.当一个副本集在Docker中运行时,它可能只暴露一个MongoDB端点。在这种情况下,无法发现副本集,指定directConnection=false会阻止您的应用程序连接到它。
In a test or development environment, you can connect to the replica set by specifying directConnection=true in your connection URI. 在测试或开发环境中,您可以通过在连接URI中指定directConnection=true来连接到副本集。In a production environment, we recommend configuring the cluster to make each MongoDB instance accessible outside of the Docker virtual network.在生产环境中,我们建议配置集群,使每个MongoDB实例都可以在Docker虚拟网络之外访问。
|
Connection Options连接选项
TLS OptionsTLS选项
The following connection string to a replica set includes tls=true option. It authenticates as user myDatabaseUser with the password D1fficultP%40ssw0rd.以下到副本集的连接字符串包括tls=true选项。它以用户myDatabaseUser身份进行身份验证,密码为D1fficultP%40ssw0rd。
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&tls=true
Alternatively, you can also use the equivalent ssl=true option:或者,您也可以使用等效的ssl=true选项:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&ssl=true
Connection Option连接选项 | Description描述 |
tls | Enables or disables TLS/SSL for the connection:为连接启用或禁用TLS/SSL:
The tls option is equivalent to the ssl option.tls选项等效于ssl选项。
If the mongosh shell specifies additional tls/ssl options from the command-line, use the --tls command-line option instead.如果mongosh shell从命令行指定了其他tls/ssl选项,请改用--tls命令行选项。
|
ssl | A boolean to enable or disable TLS/SSL for the connection:用于为连接启用或禁用TLS/SSL的布尔值:
The ssl option is equivalent to the tls option.ssl选项等效于tls选项。
If the mongosh shell specifies additional tls/ssl options from the command-line, use the --ssl command-line option instead.如果mongosh shell从命令行指定了其他tls/ssl选项,请改用--ssl命令行选项。
|
tlsCertificateKeyFile | Specifies the location of a local .pem file that contains either the client's TLS/SSL X.509 certificate or the client's TLS/SSL certificate and key.指定本地.pem文件的位置,该文件包含客户端的TLS/SSL X.509证书或客户端的TLS/SSL证书和键。
The client presents this file to the mongod / mongos instance.客户端将此文件呈现给mongod/mongos实例。
mongod / mongos logs a warning on connection if the presented X.509 certificate expires within 30 days of the mongod/mongos host system time.如果所提供的X.509证书在mongod/mongos主机系统时间后30天内过期,则mongod / mongos记录连接警告。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
|
tlsCertificateKeyFilePassword | Specifies the password to de-crypt the tlsCertificateKeyFile.指定对tlsCertificateKeyFile进行解密的密码。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
|
tlsCAFile | Specifies the location of a local .pem file that contains the root certificate chain from the Certificate Authority. 指定包含来自证书颁发机构的根证书链的本地.pem文件的位置。This file is used to validate the certificate presented by the mongod / mongos instance.此文件用于验证mongod/mongos实例提供的证书。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
|
tlsAllowInvalidCertificates | Bypasses validation of the certificates presented by the mongod / mongos instance绕过mongod/mongos实例提供的证书的验证
Set to true to connect to MongoDB instances even if the server's present invalid certificates.设置为true以连接到MongoDB实例,即使服务器存在无效证书。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
WARNING:警告: Disabling certificate validation creates a vulnerability.禁用证书验证会创建漏洞。
|
tlsAllowInvalidHostnames | Disables hostname validation of the certificate presented by the mongod / mongos instance.禁用mongod/mongos实例提供的证书的主机名验证。
Set to true to connect to MongoDB instances even if the hostname in the server certificates do not match the server's host.设置为true以连接到MongoDB实例,即使服务器证书中的主机名与服务器的主机不匹配。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
WARNING:警告: Disabling certificate validation creates a vulnerability.禁用证书验证会创建漏洞。
|
tlsInsecure | Disables various certificate validations.禁用各种证书验证。
Set to true to disable certificate validations. The exact validatations disabled vary by drivers. Refer to the Drivers documentation.设置为true可禁用证书验证。禁用的确切验证因驱动程序而异。请参阅驱动程序文档。
This connection string option is not available for the mongo shell. Use the command-line option instead.此连接字符串选项不适用于mongo shell。请改用命令行选项。
WARNING:警告: Disabling certificate validation creates a vulnerability.禁用证书验证会创建漏洞。
|
Timeout Options超时选项
Connection Option连接选项 | Description描述 |
connectTimeoutMS | The time in milliseconds to attempt a connection before timing out. The default is 10,000 milliseconds, but specific drivers might have a different default. 超时前尝试连接的时间(毫秒)。默认值为10000毫秒,但特定驱动程序可能有不同的默认值。For details, see the driver documentation.有关详细信息,请参阅驱动程序文档。
|
socketTimeoutMS | The time in milliseconds to attempt a send or receive on a socket before the attempt times out. The default is never to timeout, though different drivers might vary. 在尝试超时之前,在套接字上尝试发送或接收的时间(毫秒)。默认设置是永不超时,尽管不同的驱动程序可能会有所不同。See the driver documentation.请参阅驱动程序文档。
|
Compression Options压缩选项
Connection Option连接选项 | Description描述 |
compressors | Comma-delimited string of compressors to enable network compression for communication between this client and a mongod / mongos instance.逗号分隔的压缩器字符串,用于为此客户端和mongod/mongos实例之间的通信启用网络压缩。
You can specify the following compressors:您可以指定以下压缩机:
If you specify multiple compressors, then the order in which you list the compressors matter as well as the communication initiator. 如果指定了多个压缩器,那么列出压缩器的顺序与通信发起者一样重要。For example, if the client specifies the following network compressors "zlib,snappy" and the mongod specifies "snappy,zlib", messages between the client and the mongod uses zlib.例如,如果客户端指定以下网络压缩器"zlib,snappy",而mongod指定"snappy,zlib",则客户端和mongod之间的消息将使用zlib。
Messages are compressed when both parties enable network compression. Otherwise, messages between the parties are uncompressed.当双方都启用网络压缩时,消息会被压缩。否则,双方之间的消息将不压缩。
If the parties do not share at least one common compressor, messages between the parties are uncompressed.如果双方不共享至少一个公共压缩器,则双方之间的消息将被解压缩。
mongosh supports the uri connection string option compressors.mongosh支持uri连接字符串选项compressors。
|
zlibCompressionLevel | An integer that specifies the compression level if using zlib for network compression.如果使用zlib进行网络压缩,则指定压缩级别的整数。
You can specify an integer value ranging from -1 to 9:您可以指定一个范围在-1到9之间的整数值:
Value值 | Notes备注 |
-1
| Default compression level, usually level 6 compression.默认压缩级别,通常为6级压缩。 |
0
| No compression不压缩 |
1 - 9
| Increasing level of compression but at the cost of speed, with:以速度为代价提高压缩水平,包括:
1 providing the best speed but least compression, and1提供最佳速度但压缩最小,以及
9 providing the best compression but at the slowest speed.9提供最佳压缩,但速度最慢。
|
Supported by mongosh.由mongosh支持。
|
Connection Pool Options连接池选项
Most drivers implement some kind of connection pool handling. Some drivers do not support connection pools. See your driver documentation for more information on the connection pooling implementation. These options allow applications to configure the connection pool when connecting to the MongoDB deployment.大多数驱动程序都实现了某种连接池处理。某些驱动程序不支持连接池。有关连接池实现的更多信息,请参阅驱动程序文档。这些选项允许应用程序在连接到MongoDB部署时配置连接池。
Connection Option连接选项 | Description描述 |
maxPoolSize | The maximum number of connections in the connection pool. The default value is 100.连接池中的最大连接数。默认值为100。 |
minPoolSize | The minimum number of connections in the connection pool. The default value is 0.连接池中的最小连接数。默认值为0。
The minPoolSize option is not supported by all drivers. For information on your driver, see the Drivers documentation.并非所有驱动程序都支持minPoolSize选项。有关驱动程序的信息,请参阅驱动程序文档。
|
maxConnecting | Maximum number of connections a pool may be establishing concurrently. The default value is 2.池可以同时建立的最大连接数。默认值为2。
maxConnecting is supported for all drivers except the Rust Driver.除Rust驱动程序外,所有驱动程序都支持maxConnecting。
Raising the value of maxConnecting allows the client to establish connection to the server faster, but increases the chance of connection storms. 提高maxConnecting的值可以让客户端更快地建立与服务器的连接,但会增加连接风暴的可能性。If the value of maxConnecting is too low, your connection pool may experience heavy throttling and increased tail latency for clients checking out connections.如果maxConnecting的值太低,您的连接池可能会遇到严重的限制,并且客户端签出连接的尾部延迟会增加。
|
maxIdleTimeMS | The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed.在删除和关闭连接之前,连接在池中可以保持空闲的最大毫秒数。
This option is not supported by all drivers.并非所有驱动程序都支持此选项。
|
waitQueueMultiple | A number that the driver multiplies the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool. For default values, see the driver documentation.驱动程序将maxPoolSize值乘以的数字,以提供允许等待池中可用连接的最大线程数。有关默认值,请参阅驱动程序文档。
This option is not supported by all drivers.并非所有驱动程序都支持此选项。
|
waitQueueTimeoutMS | The maximum time in milliseconds that a thread can wait for a connection to become available. For default values, see the driver documentation.线程可以等待连接可用的最长时间(毫秒)。有关默认值,请参阅驱动程序文档。
This option is not supported by all drivers.并非所有驱动程序都支持此选项。
|
Write Concern Options写入关注选项
Write concern describes the level of acknowledgment requested from MongoDB. The write concern option is supported by the:写入关注描述了从MongoDB请求的确认级别。写关注选项得到以下支持:
You can specify the write concern both in the connection string and as a parameter to methods like insert or update. If the write concern is specified in both places, the method parameter overrides the connection-string setting.您可以在连接字符串中指定写入关注,也可以将其作为参数指定给insert或update等方法。如果在这两个位置都指定了写入关注,则方法参数将覆盖连接字符串设置。
MongoDB Atlas deployment connection strings use "majority" by default. If you don't specify write concern for an MongoDB Atlas deployment, MongoDB Atlas enforces "majority".MongoDB Atlas部署连接字符串默认使用"majority"。如果您没有为MongoDB Atlas部署指定写入关注,MongoDB Atlas将强制执行"majority"。
The following connection string to a replica set specifies "majority" write concern and a 5 second timeout using the wtimeoutMS write concern parameter:以下与副本集的连接字符串使用wtimeoutMS写入关注参数指定了"majority"写关注和5秒超时:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&w=majority&wtimeoutMS=5000
Connection Option连接选项 | Description描述 |
w | Corresponds to the write concern w Option. 对应于写入问题w选项。The w option requests acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags.w选项请求确认写入操作已传播到指定数量的mongod实例或具有指定标签的mongod实例。
You can specify a number, the string majority, or a tag set.您可以指定number、字符串majority或tag set(标记集)。
For details, see w Option.有关详细信息,请参阅w选项。
|
wtimeoutMS | Corresponds to the write concern wtimeout. wtimeoutMS specifies a time limit, in milliseconds, for the write concern.对应于写入关注wtimeout。wtimeoutMS指定写入关注的时间限制(以毫秒为单位)。
When wtimeoutMS is 0, write operations will never time out. For more information, see wtimeout.当wtimeoutMS为0时,写操作永远不会超时。有关更多信息,请参阅wtimeout。
|
journal | Corresponds to the write concern j Option option. 对应于写入关注j选项。The journal option requests acknowledgment from MongoDB that the write operation has been written to the journal. For details, see j Option.journal选项请求MongoDB确认写入操作已写入日志。有关详细信息,请参阅j选项。
If you set journal to true, and specify a w value less than 1, journal prevails.如果将journal设置为true,并指定小于1的w值,则以journal为准。
|
For more information, see Write Concern.有关更多信息,请参阅写入关注。
readConcern Options读取关注选项
For the WiredTiger storage engine, MongoDB introduces the readConcern option for replica sets and replica set shards.对于WiredTiger存储引擎,MongoDB为副本集和副本集分片引入了readConcern选项。
Read Concern allows clients to choose a level of isolation for their reads from replica sets.读取关注允许客户端为其从副本集的读取选择隔离级别。
The following connection string to a replica set specifies readConcernLevel=majority:以下与副本集的连接字符串指定readConcernLevel=majority:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&readConcernLevel=majority
Connection Option连接选项 | Description描述 |
readConcernLevel | The level of isolation. Can accept one of the following values:隔离的程度。可以接受以下值之一:
This connection string option is not available for mongosh. 此连接字符串选项不适用于mongosh。Specify the read concern as an option to the specific operation.将读取关注指定为特定操作的选项。
|
For more information, see Read Concern.有关更多信息,请参阅读取关注。
Read Preference Options读取首选项选项
Read preferences describe the behavior of read operations with regards to replica sets. 读取首选项描述了与副本集相关的读取操作的行为。These parameters allow you to specify read preferences on a per-connection basis in the connection string.这些参数允许您在连接字符串中为每个连接指定读取首选项。
For example:例如:
The following connection string to a replica set specifies secondary read preference mode and a maxStalenessSeconds value of 120 seconds:以下到副本集的连接字符串指定了secondary读取首选项模式和120秒的maxStalenessSeconds值:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&readPreference=secondary&maxStalenessSeconds=120
The following connection string to a sharded cluster specifies secondary read preference mode and a maxStalenessSeconds value of 120 seconds:以下与分片群集的连接字符串指定了secondary读取首选项模式和120秒的maxStalenessSeconds值:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@mongos1.example.com,mongos2.example.com/?readPreference=secondary&maxStalenessSeconds=120
The following connection string to a sharded cluster specifies secondary read preference mode as well as three readPreferenceTags:以下与分片集群的连接字符串指定了secondary读取首选项模式以及三个readPreferenceTags:
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@mongos1.example.com,mongos2.example.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=dc:ny&readPreferenceTags=
Order matters when using multiple readPreferenceTags. The readPreferenceTags are tried in order until a match is found. 使用多个readPreferenceTags时,顺序很重要。按顺序尝试readPreferenceTags,直到找到匹配项。Once found, that specification is used to find all eligible matching members and any remaining readPreferenceTags are ignored. 一旦找到,该规范将用于查找所有符合条件的匹配成员,并忽略任何剩余的readPreferenceTags。For details, see Order of Tag Matching.有关详细信息,请参阅标记匹配顺序。
Connection Option连接选项 | Description描述 |
readPreference | Specifies the read preferences for this connection. Possible values are:指定此连接的读取首选项。可能的值有:
Distributed transactions that contain read operations must use read preference primary. All operations in a given transaction must route to the same member.包含读取操作的分布式事务必须使用读取首选项primary。给定事务中的所有操作都必须路由到同一成员。
This connection string option is not available for the mongo shell. See cursor.readPref() and Mongo.setReadPref() instead.此连接字符串选项不适用于mongo shell。请参阅cursor.readPref()和Mongo.setReadPref()。
|
maxStalenessSeconds | Specifies, in seconds, how stale a secondary can be before the client stops using it for read operations. 以秒为单位指定在客户端停止将辅助服务器用于读取操作之前,辅助服务器的过时程度。For details, see Read Preference maxStalenessSeconds.有关详细信息,请参阅读取首选项读取首选项maxStalenessSeconds。
By default, there is no maximum staleness and clients will not consider a secondary's lag when choosing where to direct a read operation.默认情况下,没有最大的过期时间,客户端在选择将读取操作定向到何处时不会考虑辅助设备的延迟。
The minimum maxStalenessSeconds value is 90 seconds. Specifying a value between 0 and 90 seconds will produce an error. MongoDB drivers treat a maxStalenessSeconds value of -1 as "no max staleness", the same as if maxStalenessSeconds is omitted.最小maxStalenessSeconds值为90秒。指定0到90秒之间的值将产生错误。MongoDB驱动程序将maxStalenessSeconds值-1视为“无最大过时性”,就像省略maxStalennessSeconds一样。
|
readPreferenceTags | Specifies the tags document as a comma-separated list of colon-separated key-value pairs. For example,将标记文档指定为以逗号分隔的冒号分隔的键值对列表。例如,
To specify the tags document { "dc": "ny", "rack": "r1" }, use readPreferenceTags=dc:ny,rack:r1 in the connection string.要指定标签文档{ "dc": "ny", "rack": "r1" },请在连接字符串中使用readPreferenceTags=dc:ny,rack:r1。
To specify an empty tags document { }, use readPreferenceTags= without setting the value.要指定空标记文档{ },请使用readPreferenceTags=而不设置值。
To specify a list of tag documents, use multiple readPreferenceTags. For example, readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=.要指定标记文档列表,请使用多个readPreferenceTags。例如,readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=。
Order matters when using multiple readPreferenceTags. 使用多个readPreferenceTags时,顺序很重要。The readPreferenceTags are tried in order until a match is found. For details, see Order of Tag Matching.按顺序尝试readPreferenceTags,直到找到匹配项。有关详细信息,请参阅标记匹配顺序。
This connection string option is not available for the mongo shell. See cursor.readPref() and Mongo.setReadPref() instead.此连接字符串选项不适用于mongo shell。请参阅cursor.readPref()和Mongo.setReadPref()。
|
For more information, see Read preferences.有关更多信息,请参阅读取首选项。
Authentication Options身份验证选项
The following connection string to a replica set specifies the authSource to the admin database. That is, the user credentials are authenticated against the admin database.以下到副本集的连接字符串指定了admin数据库的authSource。也就是说,用户凭据将根据admin数据库进行身份验证。
mongodb://myDatabaseUser:D1fficultP%40ssw0rd@mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl&authSource=admin
If the username or password includes the following characters, those characters must be converted using percent encoding:如果用户名或密码包含以下字符,则必须使用百分比编码转换这些字符:
$ : / ? # [ ] @
Connection Option连接选项 | Description描述 |
authSource | Specify the database name associated with the user's credentials. If authSource is unspecified, authSource defaults to the defaultauthdb specified in the connection string. 指定与用户凭据关联的数据库名称。如果未指定authSource,authSource默认为连接字符串中指定的defaultauthdb。If defaultauthdb is unspecified, then authSource defaults to admin.如果未指定defaultauthdb,则authSource默认为admin。
The PLAIN (LDAP), GSSAPI (Kerberos), and MONGODB-AWS (IAM) authentication mechanisms require that authSource be set to $external, as these mechanisms delegate credential storage to external services.PLAIN(LDAP)、GSSAPI(Kerberos)和MONGODB-AWS(IAM)身份验证机制要求将authSource设置为$external,因为这些机制将凭据存储委托给外部服务。
MongoDB will ignore authSource values if no username is provided, either in the connection string or via the --username parameter.如果连接字符串中或通过--username参数未提供用户名,MongoDB将忽略authSource值。
|
authMechanismDefault: SCRAM-SHA-256 | Specify the authentication mechanism that MongoDB uses to authenticate the connection. If you don't specify an authMechanism but provide user credentials, MongoDB attempts to use SCRAM-SHA-256. If this fails, it falls back to SCRAM-SHA-1.指定MongoDB用于对连接进行身份验证的身份验证机制。如果你不指定authMechanism,但提供用户凭据,MongoDB会尝试使用SCRAM-SHA-256。如果失败,则返回SCRAM-SHA-1。
Only MongoDB Enterprise mongod and mongos instances provide GSSAPI (Kerberos) and PLAIN (LDAP) mechanisms.只有MongoDB Enterprise mongod和mongos实例提供GSSAPI(Kerberos)和PLAIN(LDAP)机制。
To use MONGODB-X509, you must have TLS/SSL Enabled.要使用MONGODB-X509,您必须启用TLS/SSL。
To use MONGODB-AWS, you must be connecting to a MongoDB Atlas cluster which has been configured to support authentication via AWS IAM credentials (an AWS access key ID and a secret access key, and optionally an AWS session token). 要使用MONGODB-AWS,您必须连接到MONGODB Atlas集群,该集群已配置为支持通过AWS IAM凭据(AWS访问键ID和秘密访问键,以及可选的AWS会话令牌)进行身份验证。The MONGODB-AWS authentication mechanism requires that the authSource be set to $external.MONGODB-AWS身份验证机制要求将authSource设置为$external。
If the AWS access key ID, secret access key, or session token are defined on your platform by using their respective AWS IAM environment variables, mongosh will use these environment variable values to authenticate automatically. You do not need to specify them in the connection string. 如果您的平台上使用各自的AWS IAM环境变量定义了AWS访问键ID、秘密访问键或会话令牌,mongosh将使用这些环境变量值自动进行身份验证。您不需要在连接字符串中指定它们。There are other methods to provide AWS credentials depending on your deployment environment and security requirements.根据您的部署环境和安全要求,还有其他方法可以提供AWS凭据。
See Connect to an Atlas Cluster for example usage of the MONGODB-AWS authentication mechanism.有关MONGODB-AWS身份验证机制的示例用法,请参阅连接到Atlas集群。
See Authentication on Self-Managed Deployments for more information about the authentication system in MongoDB. 有关MongoDB中身份验证系统的更多信息,请参阅自我管理部署上的身份验证。Also consider Use X.509 Certificates to Authenticate Clients on Self-Managed Deployments for more information on x509 authentication.还可以考虑使用X.509证书对自我管理部署上的客户端进行身份验证,以获取有关x509身份验证的更多信息。
|
authMechanismProperties | Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs.将指定authMechanism的属性指定为逗号分隔的键值对列表。
Possible key-value pairs are:可能的键值对有:
SERVICE_NAME:<string>Set the Kerberos service name when connecting to Kerberized MongoDB instances. This value must match the service name set on MongoDB instances to which you are connecting. 在连接到Kerberized MongoDB实例时设置Kerberos服务名称。此值必须与您正在连接的MongoDB实例上设置的服务名称匹配。Only valid when using the GSSAPI authentication mechanism.仅在使用GSSAPI身份验证机制时有效。
SERVICE_NAME defaults to mongodb for all clients and MongoDB instances. 对于所有客户端和mongodb实例,SERVICE_NAME默认为mongodb。If you change the saslServiceName setting on a MongoDB instance, you must set SERVICE_NAME to match that setting. Only valid when using the GSSAPI authentication mechanism.如果更改MongoDB实例上的saslServiceName设置,则必须将SERVICE_NAME设置为与该设置匹配。仅在使用GSSAPI身份验证机制时有效。
CANONICALIZE_HOST_NAME:true|falseCanonicalize the hostname of the client host machine when connecting to the Kerberos server. This may be required when hosts report different hostnames than what is in the Kerberos database. 连接到Kerberos服务器时,规范客户端主机的主机名。当主机报告的主机名与Kerberos数据库中的主机名不同时,可能需要执行此操作。Defaults to false. Only valid when using the GSSAPI authentication mechanism.默认为false。仅在使用GSSAPI身份验证机制时有效。
SERVICE_REALM:<string>Set the Kerberos realm for the MongoDB service. This may be necessary to support cross-realm authentication where the user exists in one realm and the service in another. 为MongoDB服务设置Kerberos领域。这可能是支持跨领域身份验证所必需的,其中用户存在于一个领域,服务存在于另一个领域。Only valid when using the GSSAPI authentication mechanism.仅在使用GSSAPI身份验证机制时有效。
AWS_SESSION_TOKEN:<security_token>Set the AWS session token for authentication with temporary credentials when using an AssumeRole request, or when working with AWS resources that specify this value such as Lambda. 在使用AssumeRole请求或使用指定此值的AWS资源(如Lambda)时,设置AWS会话令牌以使用临时凭据进行身份验证。Only valid when using the MONGODB-AWS authentication mechanism. You must have an AWS access key ID and a secret access key as well. 仅在使用MONGODB-AWS身份验证机制时有效。您还必须拥有AWS访问键ID和秘密访问键。See Connect to an Atlas Cluster for example usage.有关示例用法,请参阅连接到Atlas集群。
ENVIRONMENT:<string>Set the OpenID Connect (OIDC) environment. For:设置OpenID连接(OIDC)环境。适用于:
- Microsoft Azure, set
ENVIRONMENT:azure
- Google Cloud Platform, set
ENVIRONMENT:gcp
You must also set authMechanism to MONGODB-OIDC.您还必须将authMechanism设置为MONGODB-OIDC。
|
gssapiServiceName | Set the Kerberos service name when connecting to Kerberized MongoDB instances. This value must match the service name set on MongoDB instances to which you are connecting.在连接到Kerberized MongoDB实例时设置Kerberos服务名称。此值必须与您正在连接的MongoDB实例上设置的服务名称匹配。
gssapiServiceName defaults to mongodb for all clients and MongoDB instances. gssapiServiceName默认为所有客户端和mongodb实例的mongodb。If you change saslServiceName setting on a MongoDB instance, you must set gssapiServiceName to match that setting.如果更改MongoDB实例上的saslServiceName设置,则必须将gssapiServiceName设置为与该设置匹配。
gssapiServiceName is a deprecated aliases for authMechanismProperties=SERVICE_NAME:mongodb. gssapiServiceName是authMechanismProperties=SERVICE_NAME:mongodb的已弃用别名。For more information on which options your driver supports and their relative priority to each other, reference the documentation for your preferred driver version.有关驱动程序支持哪些选项及其相对优先级的更多信息,请参阅首选驱动程序版本的文档。
|
Server Selection and Discovery Options服务器选择和发现选项
MongoDB provides the following options to configure how MongoDB drivers and mongos instances select a server to which to direct read or write operations.MongoDB提供以下选项来配置MongoDB驱动程序和mongos实例如何选择要直接进行读写操作的服务器。
Connection Option连接选项 | Description描述 |
localThresholdMS | The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances. 用于在多个合适的MongoDB实例中进行选择的延迟窗口的大小(以毫秒为单位)。Default: 15 milliseconds.
All drivers use localThresholdMS. Use the localThreshold alias when specifying the latency window size to mongos.所有驱动程序都使用localThresholdMS。在为mongos指定延迟窗口大小时,请使用localThreshold别名。
|
serverSelectionTimeoutMS | Specifies how long (in milliseconds) to block for server selection before throwing an exception. Default: 30,000 milliseconds.指定在抛出异常之前阻止服务器选择的时间(以毫秒为单位)。默认值:30000毫秒。
|
serverSelectionTryOnce | Single-threaded drivers only. When true, instructs the driver to scan the MongoDB deployment exactly once after server selection fails and then either select a server or raise an error. 仅限单线程驱动程序。如果为true,则指示驱动程序在服务器选择失败后仅扫描一次MongoDB部署,然后选择服务器或引发错误。When false, the driver blocks and searches for a server up to the serverSelectionTimeoutMS value. Default: true.如果为false,驱动程序将阻止并搜索服务器,最大值为serverSelectionTimeoutMS。默认值:true。
Multi-threaded drivers and mongos do not support serverSelectionTryOnce.多线程驱动程序和mongos不支持serverSelectionTryOnce。
|
heartbeatFrequencyMS | heartbeatFrequencyMS controls when the driver checks the state of the MongoDB deployment. 控制驱动程序何时检查MongoDB部署的状态。Specify the interval (in milliseconds) between checks, counted from the end of the previous check until the beginning of the next one.指定检查之间的间隔(以毫秒为单位),从上一次检查结束到下一次检查开始计算。
Default:
Single-threaded drivers: 60 seconds.单线程驱动程序:60秒。
Multi-threaded drivers: 10 seconds.多线程驱动程序:10秒。
mongos does not support changing the frequency of the heartbeat checks.不支持更改心跳检查的频率。
|
socketCheckIntervalMS | Single-threaded clients only. Controls how often the client checks the state of the TCP connection to the MongoDB deployment. If you specify a lower value, the client detects network issues faster but uses more CPU. Default: 5 seconds.仅限单线程客户端。控制客户端检查到MongoDB部署的TCP连接状态的频率。如果指定较低的值,客户端会更快地检测到网络问题,但会使用更多的CPU。默认值:5秒。
This option is not supported by all drivers. Refer to the Drivers documentation.并非所有驱动程序都支持此选项。请参阅驱动程序文档。
|
Miscellaneous Configuration其他配置
Connection Option连接选项 | Description描述 |
appName | Specify a custom app name. The app name appears in:指定自定义应用程序名称。应用程序名称显示在:
The appName connection option is available for:appName连接选项可用于:
|
retryReads | Enables retryable reads.启用可重试的读取。
Possible values are:可能的值有:
mongosh does not support retryable reads.不支持可重试的读取。
|
retryWrites | Enable retryable writes.启用可重试写入。
Possible values are:可能的值有:
MongoDB drivers retry transaction commit and abort operations regardless of the value of retryWrites. MongoDB驱动程序重试事务提交和中止操作,而不管retryWrites的值如何。For more information on transaction retryability, see Transaction Error Handling.有关事务可重试性的更多信息,请参阅事务错误处理。
|
uuidRepresentation | Possible values are:可能的值有:
standard - The standard binary representation.标准二进制表示法。
csharpLegacy - The default representation for the C# driver.C#驱动程序的默认表示形式。
javaLegacy - The default representation for the Java driver.Java驱动程序的默认表示形式。
pythonLegacy - The default representation for the Python driver.Python驱动程序的默认表示。
For the default, see the Drivers documentation for your driver.有关默认设置,请参阅驱动程序的驱动程序文档。
Not all drivers support the uuidRepresentation option. For information on your driver, see the drivers documentation.并非所有驱动程序都支持uuidRepresentation选项。有关驱动程序的信息,请参阅驱动程序文档。
|
loadBalanced | Specifies whether the client is connecting to a load balancer. This option is false by default.指定客户端是否连接到负载平衡器。默认情况下,此选项为false。
You can set this option to true only if you meet the following requirements:只有满足以下要求时,才能将此选项设置为true:
|
srvMaxHosts | Specifies the number of mongos connections that can be created for sharded topologies. 指定可以为分片拓扑创建的mongos连接数。Set this option to a non-negative integer. 0 is the default value and means there is no limit on the number of mongos connections.将此选项设置为非负整数。0是默认值,表示mongos连接的数量没有限制。
|