Docs Menu

SOCKS5 프록시를 사용하여 MongoDB에 연결하기

이 가이드에서는 SOCKS5 프록시를 사용하여 MongoDB에 연결하는 방법을 배울 수 있습니다. SOCKS5는 프록시 서버를 통해 네트워크 서비스와 통신하기 위한 표준화된 프로토콜입니다.

SOCKS 프로토콜에 대해 자세히 알아보려면5 SOCKS에대한 Wikipedia 항목을 참조하세요 .

The proxy settings specify the SOCKS5 proxy server address and your authentication credentials. You can specify your settings in an instance of MongoClientSettings or in your 연결 문자열.

중요

다음 중 하나가 true인 경우 드라이버는 프록시 설정을 무시합니다.

다음 표에서는 SOCKS5 클라이언트 옵션을 설명합니다.

이름
허용되는 값
설명

proxyHost

문자열

Specifies the SOCKS5 proxy IPv4 address, IPv6 address, or hostname. You must provide this value to connect to a SOCKS5 proxy. | | 기본값: null

proxyPort

음수가 아닌 정수

Specifies the TCP port number of the SOCKS5 proxy server.

Default: 1080 when you set proxyHost

proxyUsername

문자열

Specifies the username for authentication to the SOCKS5 proxy server. The driver ignores null and empty string values for this setting. The driver requires that you pass values for both proxyUsername and proxyPassword or that you omit both values. | | 기본값: null

proxyPassword

문자열

SOCKS5 프록시 서버에 대한 인증을 위한 비밀번호를 지정합니다. 드라이버는 이 설정의 null 및 빈 문자열 값을 무시합니다. 드라이버에서는 proxyUsernameproxyPassword에 대한 값을 모두 전달하거나 두 값을 모두 생략해야 합니다.

Default: null

다음 예시에서는 SOCKS5 프록시를 사용하여 MongoDB에 연결하는 MongoClient를 인스턴스화하는 방법을 보여 줍니다. 프록시 설정은 MongoClientSettings 인스턴스 또는 연결 문자열에서 지정할 수 있습니다. 이 예시에서는 SOCKS5 프록시 설정 섹션에 설명된 자리 표시자 값을 사용합니다. 자리 표시자를 프록시 설정으로 바꿉니다.

다음 코드 예시에서는 MongoClientSettings 빌더를 사용하여 SOCKS5 프록시 설정을 지정하는 방법을 보여 줍니다.

MongoClient mongoClient = MongoClients.create(
MongoClientSettings.builder()
.applyConnectionString(
new ConnectionString("mongodb+srv://myDatabaseUser:myPassword@example.org/"))
.applyToSocketSettings(builder ->
builder.applyToProxySettings(proxyBuilder ->
proxyBuilder
.host("<proxyHost>")
.port(<proxyPort>)
.username("<proxyUsername>")
.password("<proxyPassword>")
)
).build());

다음 코드 예시에서는 연결 문자열에 SOCKS5 프록시 설정을 지정하는 방법을 보여줍니다.

String connectionString = "mongodb+srv://myDatabaseUser:myPassword@example.org/" +
"?proxyHost=<proxyHost>" +
"&proxyPort=<proxyPort>" +
"&proxyUsername=<proxyUsername>" +
"&proxyPassword=<proxyPassword>";
MongoClient mongoClient = MongoClients.create(connectionString);

이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 문서를 참조하세요.