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
/ /

연결 옵션 지정

이 섹션에서는 Rust 운전자 에서 사용할 수 있는 MongoDB 연결 및 인증 옵션에 대해 설명합니다. 연결 URI(연결 문자열 이라고도 함)를 사용하거나 ClientOptions 를 만들 때 인스턴스 에 필드를 설정하여 연결을 구성할 수 Client 있습니다.

연결 URI를 Client::with_uri_str 메서드에 전달하는 경우 문자열에 연결 옵션을 <name>=<value> 쌍으로 포함할 수 있습니다. 다음 예시 값이 60000connectTimeoutMS 옵션과 값이 truetls 옵션이 포함된 연결 URI를 보여 줍니다.

use mongodb::Client;
let uri = "mongodb://<hostname>:<port>/?connectTimeoutMS=60000&tls=true";
let client = Client::with_uri_str(uri).await?;

연결 URI에 포함하는 대신 ClientOptions 인스턴스 에서 연결 옵션을 설정하다 수 있습니다. ClientOptions 인스턴스 사용하여 연결을 구성하면 런타임에 설정을 변경하고 컴파일 중에 오류를 포착하기가 더 쉽습니다. 다음 예시 ClientOptions 를 사용하여 연결 옵션을 설정하다 방법을 보여 줍니다.

use std::time::Duration;
use mongodb::{Client, options::ClientOptions};
let uri = "mongodb://<hostname>:<port>/";
let mut client_options = ClientOptions::parse(uri).await?;
client_options.connect_timeout = Some(Duration::from_secs(60000));
//Set additional options on client_options here
let client = Client::with_options(client_options)?;

다음 섹션에서는 Rust 운전자 에서 사용할 수 있는 연결 옵션에 대해 설명합니다. 연결 옵션의 전체 목록을 보려면 연결 문자열에 대한 서버 매뉴얼 가이드 의 연결 문자열 옵션 섹션을 참조하세요.

옵션 이름
허용되는 값
기본값
설명

압축기

쉼표로 구분된 문자열 목록

none

Specifies compressors that the Client instance uses in the specified order.
To learn more about network compression, see the Network Compression guide.

zlibCompressionLevel

0 ~ 9사이의 정수

6

Specifies the level field of the zlib compression if you use that compressor. A higher level value results in more compression, which is slower.
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.
옵션 이름
허용되는 값
기본값
설명

connectTimeoutMS

Non-negative integer

10000 (10초)

서버에 연결을 시도할 때 각 기본 TCP 스트림에 전달되는 연결 제한 시간(밀리초)을 지정합니다.

옵션 이름
허용되는 값
기본값
설명

heartbeatFrequencyMS

500보다 크거나 이와 동일한 정수

10000 (10초)

각 모니터링 스레드가 서버 검사를 수행하는 사이에 대기하는 시간(밀리초)을 지정합니다.

최대 보관 기간

-1, 또는 다음보다 크거나 같은 정수 90

-1

Specifies the maximum lag, in seconds, behind the primary node that a secondary node can 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.

serverSelectionTimeoutMS

Non-negative integer

30000 (30초)

Client 인스턴스가 시간 초과되기 전에 작업에 대한 서버를 선택하려고 할 때 대기하는 시간(밀리초)을 지정합니다.

옵션 이름
허용되는 값
기본값
설명

authMechanism

문자열

none

사용할 인증 메커니즘을 지정합니다. 이 옵션을 지정하지 않으면 드라이버는 기본 인증 메커니즘을 사용합니다. Rust 드라이버의 인증에 대해 자세히 알아보려면 인증 메커니즘 가이드를 참조하세요.

authMechanismProperties

문자열

none

authMechanism 옵션에 설정된 인증 메커니즘에 대한 추가 속성을 지정합니다.

authSource

문자열

설명 참조

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.

TLS

부울

false

Specifies the TLS configuration for the Client instance to use in its connections with the server.
By default, TLS is off.

tlsAllowInvalidCertificates

부울

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

문자열

설명 참조

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

문자열

none

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

문자열

none

키가 암호화됨 된 경우 인증서 파일 의 개인 키를 해독하기 위한 비밀번호를 지정합니다.

tlsInsecure

부울

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.
옵션 이름
허용되는 값
기본값
설명

directConnection

부울

false

cluster의 모든 서버를 검색하여 연결하는 대신 Client 인스턴스를 단일 호스트에 직접 연결할지 여부를 지정합니다.

journal

부울

false

작업이 온디스크 저널로 전파되었음을 확인 요청합니다.

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.

readConcernLevel

문자열

none

Specifies the default read concern for operations performed on the Client instance.
To learn more, see Read Concern in the Server manual.

읽기 설정

문자열

primary

Specifies how the driver routes a read operation to members of a replica set.
To learn more, see Read Preference in the Server manual.

readPreferenceTags

쉼표로 구분된 키-값 쌍 목록

none

Specifies which replica set members are considered for operations. Each instance of this key is a separate tag set.
The driver checks each tag set until it finds one or more servers with each tag in the set.

복제본 세트

문자열

none

Client 인스턴스가 연결되는 복제본 세트의 이름을 지정합니다.

retryReads

부울

true

작업이 실패할 경우 클라이언트가 읽기 작업을 다시 시도할지 여부를 지정합니다.

w

음수가 아닌 정수 또는 문자열

none

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

시간 초과 없음

Specifies a time limit, in milliseconds, for the write concern.
If an operation has not propagated to the requested level within the time limit, the driver raises an error.
옵션 이름
허용되는 값
기본값
설명

maxIdleTimeMS

Non-negative integer

0

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.

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 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.

연결 풀에 대한 자세한 내용은 연결 풀 가이드 참조하세요.

옵션 이름
허용되는 값
기본값
설명

앱 이름

문자열

none

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.

ClientOptions Rust 운전자 의 에 대한 자세한 내용은 ClientOptions API 설명서를 참조하세요.

돌아가기

연결 대상 선택

이 페이지의 내용