Docs Menu
Docs Home
/ / /
Java Reactive Streams 드라이버
/

연결 URI 옵션 지정

이 페이지의 내용

  • 개요
  • 연결 URI 사용
  • 연결 옵션
  • 인증
  • 연결 구성
  • 연결 풀 구성
  • CompressorConfiguration
  • 일반 구성
  • 프록시 구성
  • 읽기 설정 구성
  • 복제본 세트 구성
  • 서버 구성
  • SRV 구성
  • 쓰기 고려 구성

이 섹션에서는 Java Reactive Streams 운전자 에서 연결 URI의 매개변수로 전달할 수 있는 MongoDB 연결 및 인증 옵션에 대해 설명합니다.

연결 URI를 MongoClient 생성자에 전달하는 경우 string 에 연결 옵션을 <name>=<value> 쌍으로 포함할 수 있습니다. 다음 예시 에서 연결 URI에는 값이 60000connectTimeoutMS 옵션과 값이 truetls 옵션이 포함되어 있습니다.

public class MongoConnection {
public static void main(String[] args) {
String uri = "mongodb://<hostname>:<port>/?connectTimeoutMS=60000&tls=true";
try (MongoClient client = MongoClients.create(uri)) {
// Use client here
}
}
}

다음 섹션에서는 Java Reactive Streams 운전자 에서 사용할 수 있는 연결 옵션에 대해 설명합니다. 이러한 옵션을 연결 URI의 매개 변수로 전달하여 클라이언트 의 동작을 지정할 수 있습니다.

연결 옵션
설명
authMechanism
Sets the mechanism the Java Reactive Streams driver uses to authenticate the
application. Valid options are defined in the Class ConnectionString API documentation.

Data Type: String
Default: "SCRAM-SHA-256" when connecting to MongoDB v4.0 or later.
"SCRAM-SHA-1" when connecting to MongoDB v3.0 through v3.13.
Connection URI Example: authMechanism=MONGODB-X509
authMechanismProperties
Sets options specific to the authentication mechanism.

Data Type: String
Default: ""
Connection URI Example: authMechanismProperties=AWS_SESSION_TOKEN:12435
authSource
Sets the source of authentication credentials. The source is typically a
database. This option is only respected when authMechanism is set
to MONGO-CR.

Data Type: String
Default: The database in the connection URI, or "admin" if none is provided
Connection URI Example: authSource=admin
사용자 이름
Sets the username for authentication. When this option is included in a connection
URI, you must percent-escape it.

Data Type: String
Default: ""
Connection URI Example: username=my+user
비밀번호
Sets the password for authentication. When this option is included in a connection
URI, you must percent-escape it.

Data Type: String
Default: ""
Connection URI Example: password=strong+password
연결 옵션
설명
connectTimeoutMS
Sets the number of milliseconds the connection can take before timing out. If an
operation doesn't finish in the specified time, the Java Reactive Streams driver raises a timeout exception.

Data Type: Integer
Default: null
Connection URI Example: connectTimeoutMS=6000
maxIdleTimeMS
Sets the maximum idle time in milliseconds of a pooled connection. If an
operation doesn't finish in the specified time, the Java Reactive Streams driver
closes the connection.

Data Type: Integer
Default: null
Connection URI Example: maxIdleTimeMS=6000
maxLifeTimeMS
Sets the maximum lifetime in milliseconds of a pooled connection. If an
operation doesn't finish in the specified time, the Java Reactive Streams driver
closes the connection.

Data Type: Integer
Default: null
Connection URI Example: maxLifeTimeMS=6000
socketTimeoutMS
Sets the number of milliseconds a recieve on a socket can take before timing out. If an
operation doesn't finish in the specified time, the Java Reactive Streams driver raises a timeout exception.

Data Type: Integer
Default: null
Connection URI Example: socketTimeoutMS=6000
ssl
Sets whether to connect using TLS/SSL.

Data Type: boolean
Default: null
Connection URI Example: ssl=true
sslInvalidHostNameAllowed
Allows invalid host names for TLS/SSL connections.

Data Type: boolean
Default: null
Connection URI Example: sslInvalidHostNameAllowed=true
TLS
Sets whether to connect using TLS. Supersedes the ssl option.

Data Type: boolean
Default: null
Connection URI Example: tls=true
tlsAllowInvalidHostnames
Allows invalid host names for TLS connections. Supersedes the
sslInvalidHostNameAllowed option.

Data Type: boolean
Default: null
Connection URI Example: tlsAllowInvalidHostnames=true
tlsInsecure
Enables insecure TLS connections when connecting using TLS.

Data Type: boolean
Default: null
Connection URI Example: tlsInsecure=true
연결 옵션
설명
maxConnecting
Sets the maximum number of connections a pool can establish concurrently.

Data Type: Integer
Default: null
Connection URI Example: maxConnecting=5
maxPoolSize
Sets the maximum number of connections in the connection pool.

Data Type: Integer
Default: null
Connection URI Example: maxPoolSize=5
minPoolSize
Sets the minimum number of connections in the connection pool.

Data Type: Integer
Default: null
Connection URI Example: minPoolSize=3
waitQueueTimeoutMS
Sets the maximum amount of time to wait in milliseconds before either
an in-use connection becomes available or a connection is created and
starts becoming established.

Data Type: Integer
Default: null
Connection URI Example: waitQueueTimeoutMS=6000
연결 옵션
설명
압축기
Sets preferred compression types, in order, for wire-protocol messages sent to
or received from the server. Compression types must be passed in as a
comma-separated list. The driver uses the first of these compression types
that the server supports.

Data Type: String
Default: null
Connection URI Example: compressors=snappy,zstd,zlib
zlibCompressionLevel
Sets the compression level for zlib to use. This option accepts
an integer value between -1 and 9:

- -1: (Default). zlib uses its default compression level (usually 6).
- 0: No compression.
- 1: Fastest speed but lowest compression.
- 9: Best compression but slowest speed.

Data Type: Integer
Default: -1
Connection URI Example: zLibCompressionLevel=3
연결 옵션
설명
directConnection
Sets whether the driver connects directly to the host.

Data Type: boolean
Default: null
Connection URI Example: directConnection=true
loadBalanced
Sets whether or not the driver is connecting to MongoDB using a load
balancer. If true, the driver assumes that it is connecting through a
load balancer.

Data Type: boolean
Default: null
Connection URI Example: directConnection=true
retryWrites
Sets whether or not the driver retries supported write operations if
they fail due to a network error.

Data Type: boolean
Default: True
Connection URI Example: retryWrites=true
retryReads
Sets whether or not the driver retries supported read operations if
they fail due to a network error.

Data Type: boolean
Default: True
Connection URI Example: retryReads=true
uuidRepresentation
Sets the mechanism the Java Reactive Streams driver uses to encode instances of
UUID. See the Uuid Representation API documentation for a list of all
valid options.

Data Type: String
Default: unspecified
Connection URI Example: uuidRepresentation=unspecified
연결 옵션
설명
proxyHost
Establishes the SOCKS5 proxy host to establish a connection through.
The value of the proxyHost can be a valid IPv4 address, IPv6
address, or a domain name.
Required if either proxyPassword, proxyUsername or proxyPort are specified.

Data Type: String
Default: null
Connection URI Example: proxyHost=example.com
proxyPort
Sets the port number for the SOCKS5 proxy server. Must be a non-negative integer.

Data Type: Integer
Default: null
Connection URI Example: proxyPort=27
proxyUsername
Sets the username for authenticating with the proxy server. Required if proxyPassword is specified.

Data Type: String
Default: null
Connection URI Example: proxyUsername=example
proxyPassword
Sets the password for authenticating with the proxy server. Required if
proxyPassword is specified.

Data Type: String
Default: null
Connection URI Example: proxyPassword=password
연결 옵션
설명
읽기 설정
Sets the read preference for this connection. Enumerated values are:
primary, primaryPreferred, secondary, secondaryPreferred, and nearest.

Data Type: Enum
Default: primary
Connection URI Example: readPreference.primary
readPreferenceTags
Specifies a tag set as a comma-separated list of
colon-separated key-value pairs, e.g. dc:ny,rack:1.
Spaces are stripped from beginning and end of all keys and values. To
specify a list of tag sets, use multiple readPreferenceTags, separated
by semicolons. To learn more about readPreferenceTags, see the Class ConnectionString API documentation.

Data Type: String
Default: null
Connection URI Example: readPreferenceTags=dc:ny
최대 보관 기간
Sets the maximum staleness in seconds. To learn more about staleness,
see the Class ConnectionString API documentation.

Data Type: Integer
Default: null
Connection URI Example: maxStalenessSeconds=60
연결 옵션
설명
복제본 세트
Specifies the name of the replica set to connect to.

Data Type: String
Default: null
Connection URI Example: replicaSet=replicaSet
연결 옵션
설명
앱 이름
Sets the logical name of the application.
The application name may be used by the client to identify the
application to the server,
for use in server logs, slow query logs, and profile collection.

Data Type: String
Default: null
Connection URI Example: appName=name
heartbeatFrequencyMS
The frequency in milliseconds of the driver determining the current state of each server in the cluster.

Data Type: Integer
Default: null
Connection URI Example: heartbeatFrequencyMS=6000
localThresholdMS
Sets a ping time threshold for choosing among multiple MongoDB servers
to send a request. When this value is set, the driver will only send
that request to a server whose
ping time is less than or equal to the server with the fastest ping time plus the local threshold.

Data Type: Integer
Default: null
Connection URI Example: localThresholdMS=6000
serverMonitoringMode
Sets the server monitoring mode, which defines the monitoring protocol to use. The enumerated values are: stream, poll, and auto.

Data Type: Enum
Default: auto
Connection URI Example: serverMonitoringMode.auto
serverSelectionTimeoutMS
Sets how long the driver will wait for server selection to succeed before throwing an exception.

Data Type: Integer
Default: null
Connection URI Example: serverSelectionTimeoutMS=6000
연결 옵션
설명
srvServiceName
Sets the SRV service name. See
API documentation to learn more.

Data Type: String
Default: "mongodb"
Connection URI Example: srvServiceName=mongodb
srvMaxHosts
Sets the maximum number of hosts from the SRV record to connect to.

Data Type: Integer
Default: null
Connection URI Example: srvMaxHosts=5
연결 옵션
설명
안전한
Sets whether the driver ensures that all writes are acknowledged by the
MongoDB server, or else throws an exception. If false, the driver
does not ensure that all writes are acknowledged by the MongoDB server.

Data Type: boolean
Default: null
Connection URI Example: safe=true
journal
Sets whether the driver waits for the server to group commit to the
journal file on disk.

Data Type: boolean
Default: null
Connection URI Example: journal=true
w
If set, the driver adds { w : wValue } to all write commands. If set,
implies that safe=True.

Data Type: Integer or String
Default: null
Connection URI Example: w=60
wtimeoutMS
If set, The driver adds { wtimeout : ms } to all write commands. If
set, implies safe=true. This option is used in combination with w.

Data Type: Integer
Default: null
Connection URI Example: wtimeoutMS=6000

이 섹션의 연결 옵션에 대한 자세한 내용은 데이터베이스 및 컬렉션 가이드 를 참조하세요.

돌아가기

연결 대상 선택