Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /

Opciones de conexión

En esta guía, aprenderá sobre las opciones de conexión y autenticación de MongoDB. Puede configurar las opciones de conexión como parámetros de su cadena de conexión para especificar cómo... Client instancia se comporta mientras está conectada al servidor.

Nombre de la opción
Valores permitidos
Valor por defecto
Descripción

appName

String

Ninguno

Specifies the application name that the Client instance sends to the server as part of the handshake.
Specifying an appName can help you use the server logs to determine which Client instance is connected to the server.

mecanismo de autenticación

String

Ninguno

Especifica qué mecanismo de autenticación utilizar. Si no se especifica esta opción, el driver utiliza el mecanismo de autenticación por defecto. Para obtener más información sobre la autenticación en el driver de Rust, consulta la guía sobre Mecanismos de autenticación.

authMechanismProperties

String

Ninguno

Especifica más propiedades para el mecanismo de autenticación establecido en la opción authMechanism.

authSource

String

Ver descripción

Specifies the database used to authenticate.
This option defaults to admin for SCRAM-based authentication mechanisms, $external for the MONGODB-X509 mechanism, and the database name or $external for the PLAIN mechanism.

compresores

Una lista de cadenas separadas por comas

Ninguno

Especifica los compresores que la instancia Client utiliza en el orden especificado. Para obtener más información sobre la compresión de red, consulta la guía Compresión de red.

connectTimeoutMS

Non-negative integer

10000 (10 segundos)

Especifica el tiempo de espera de conexión, en milisegundos, que se pasa a cada flujo TCP subyacente al intentar conectarse al servidor.

directConnection

Booleano

false

Especifica si la instancia Client se conecta directamente a un solo host en vez de descubrir y conectarse a todos los servidores del clúster.

heartbeatFrequencyMS

entero mayor o igual a 500

10000 (10 segundos)

Especifica la cantidad de tiempo en milisegundos que cada hilo de supervisión espera entre ejecuciones de pruebas al servidor.

journal

Booleano

false

Solicita confirmación de que la operación se propagó al registro en disco.

localThresholdMS

Non-negative integer

15

Specifies the amount of time in milliseconds that the average round-trip time between the driver and server can last compared to the shortest round-trip time of all the suitable servers.
A value of 0 indicates that there is no latency window, so only the server with the lowest average round-trip time is eligible.

maxIdleTimeMS

Non-negative integer

0 (no limit)

Specifies the amount of time in milliseconds that a connection can remain idle in a connection pool before the server closes it.
A value of 0 indicates that the client does not close idle connections. Set this value higher than your application's expected idle period but lower than firewall or proxy connection timeouts to prevent unexpected disconnections.

maxStalenessSeconds

-1o cualquier número entero mayor o igual a 90

-1

Specifies the maximum lag, in seconds, behind the primary node that a secondary node can be to be considered for the given operation.
The value of this option must be at least 90, or the operation raises an error. A value of -1 means there is no maximum lag.

maxPoolSize

Non-negative integer

10

Specifies the maximum number of connections that the Client instance can create in a connection pool for a given server.
If you attempt an operation while the value of maxPoolSize connections are checked out, the operation waits until an in-progress operation finishes and the connection returns to the pool.

minPoolSize

Non-negative integer

0

Specifies the minimum number of connections that are available in a server's connection pool at a given time.
If fewer than minPoolSize connections are in the pool, the server adds connections in the background up to the value of minPoolSize.

readConcernLevel

String

Ninguno

Especifica la preocupación de lectura predeterminada para las operaciones realizadas en la instancia Client. Para obtener más información, consulte Lea la preocupación en el manual del servidor.

readPreference

String

primary

Especifica cómo el driver enruta una operación de lectura a los nodos de un conjunto de réplicas. Para aprender más, consulta Preferencia de lectura en el manual del servidor.

readPreferenceTags

Una lista de pares de clave-valor separados por comas

Ninguno

Especifica cuáles miembros del conjunto de réplicas se consideran para las operaciones. Cada instancia de esta clave es un conjunto de etiquetas independiente. El controlador revisa cada conjunto de etiquetas hasta que encuentra uno o más servidores con cada etiqueta en el conjunto.

replicaSet

String

Ninguno

Especifica el nombre del conjunto de réplicas al que se conecta la instancia Client.

retryReads

Booleano

true

Especifica si el cliente reintenta una operación de lectura si la operación falla.

serverSelectionTimeoutMS

Non-negative integer

30000 (30 segundos)

Especifica la cantidad de tiempo en milisegundos que la instancia Client espera al intentar seleccionar un servidor para una operación antes de que se agote el tiempo.

tls

Booleano

false

Especifica la configuración de TLS que la instancia Client debe usar en sus conexiones con el servidor. Por defecto, TLS está desactivado.

tlsPermitirCertificadosInválidos

Booleano

false

Specifies whether the Client instance returns an error if the server presents an invalid certificate.
We recommend that you set this option to true only in testing environments to avoid creating vulnerabilities in your application.

tlsCAFile

String

Ver descripción

Specifies the path to the certificate authority (CA) file that the Client instance uses for TLS.
If you do not specify this option, the driver uses the Mozilla root certificates from the webpki-roots crate.

tlsCertificateKeyFile

String

Ninguno

Specifies the path to the certificate file that the Client instance presents to the server to verify its identify.
If you do not set this option, the Client instance does not attempt to verify its identity to the server.

tlsCertificateKeyFilePassword

String

Ninguno

Especifica la contraseña para descifrar la clave privada en su archivo de certificado, si la clave está cifrada.

tlsInsecure

Booleano

false

Specifies whether the Client instance returns an error if the server presents an invalid certificate.
We recommend that you set this option to true only in testing environments to avoid creating vulnerabilities in your application.

w

Entero o cadena no negativo

Ninguno

Requests acknowledgment that the operation has propagated to a specific number or variety of servers.
To learn more, see Write Concern in the Server manual.

wTimeoutMS

Non-negative integer

Sin tiempo de espera

Especifica un límite de tiempo, en milisegundos, para el nivel de confirmación de escritura (write concern). Si una operación no se ha propagado al nivel solicitado dentro del límite de tiempo, el driver genera un error.

zlibCompressionLevel

Entero entre -1 y 9 (inclusive)

-1

Specifies the level field of the zlib compression if you use that compressor.
Setting a value of -1 selects the default compression level (6).
Setting a value of 0 specifies no compression, and setting a value of 9 specifies maximum compression.
To learn more about network compression, see the Network Compression guide.

Para ver una lista completa de opciones de conexión, visita la sección de Opciones de cadena de conexión de la entrada del manual del servidor sobre cadenas de conexión.

Volver

Guía de Conexión