개요
이 페이지에서는 Node.js 드라이버에서 사용할 수 있는 연결 옵션과 이러한 옵션을 MongoDB 연결에 적용하는 방법을 설명합니다.
연결 옵션 지정 방법
The following sections describe how you can specify connection options by using a connection string or a MongoClientOptions object.
연결 문자열 사용
You can include connection options in a connection string as <name>=<value> pairs. Pass the connection string to the MongoClient constructor. In the following example, the connection string contains the connectTimeoutMS option with a value of 60000 and the tls option with a value of true:
const uriClient = new MongoClient( 'mongodb://localhost:27017/?connectTimeoutMS=60000&tls=true');연결 문자열 옵션에 대한 자세한 내용은 MongoDB 서버 설명서의 연결 문자열 옵션을 참조하십시오.
MongoClientOptions 객체를 사용하세요.
You can pass a MongoClientOptions object to the MongoClient constructor to configure connection settings in code. Configuring the connection this way makes it easier to change settings at runtime and helps you catch errors during compilation. This approach also provides more configuration options than the connection string.
The following example sets the connectTimeoutMS option to 60000 milliseconds and enables TLS:
const optionsClient = new MongoClient(uri, { connectTimeoutMS: 60000, tls: true,});복제본 세트 옵션
직접 연결
모든 작업을 호스트에 강제로 디스패치할지 여부를 지정합니다. 이 옵션을 지정하면 드라이버는 SRV 연결 형식을 허용하지 않습니다. 대신 표준 연결 URI 형식을 사용해야 합니다. SRV 연결 및 표준 연결 형식에 대해 자세히 학습하려면 MongoDB Server 매뉴얼의 연결 문자열 가이드를 참조하세요.
호스팅하다 이름을 두 개 이상 지정하는 경우 이 속성 false(으)로 설정하다 해야 합니다.
데이터 유형: boolean
기본값: false
예시:
const directConnectionUriClient = new MongoClient( 'mongodb://localhost:27017/?directConnection=true');복제본 세트
연결할 복제본 세트의 이름입니다.
데이터 유형: string
기본값: null
예시:
const replicaSetUriClient = new MongoClient( 'mongodb://localhost:27017/?replicaSet=rs0');직접 연결
모든 작업을 호스트에 강제로 디스패치할지 여부를 지정합니다. 이 옵션을 지정하면 드라이버는 SRV 연결 형식을 허용하지 않습니다. 대신 표준 연결 URI 형식을 사용해야 합니다. SRV 연결 및 표준 연결 형식에 대해 자세히 학습하려면 MongoDB Server 매뉴얼의 연결 문자열 가이드를 참조하세요.
호스팅하다 이름을 두 개 이상 지정하는 경우 이 속성 false(으)로 설정하다 해야 합니다.
데이터 유형: boolean
기본값: false
예시:
const directConnectionClient = new MongoClient(uri, { directConnection: true,});복제본 세트
연결할 복제본 세트의 이름입니다.
데이터 유형: string
기본값: null
예시:
const replicaSetClient = new MongoClient(uri, { replicaSet: 'rs0',});TLS 옵션
TLS 활성화
서버 연결에 TLS를 요구할지 여부를 지정합니다. "mongodb+srv" 체계를 사용하거나 다른 TLS 옵션을 지정하는 경우 이 옵션의 기본값은 true입니다. 그렇지 않으면 기본값은 false입니다.
The ssl option is an alias for the tls option.
데이터 유형: boolean
기본값: false
예시:
const tlsUriClient = new MongoClient('mongodb://localhost:27017/?tls=true');CA 파일을 지정하십시오.
The tlsCAFile option specifies the path to a file with either a single or bundle of certificate authorities to trust when making a TLS connection. To learn more about setting this option, see the Provide Certificate Filepaths section of the TLS guide.
데이터 유형: string
기본값: null
예시:
const tlsCaFileUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsCAFile=/path/to/ca.pem');클라이언트 인증서 키 파일을 지정하십시오.
The tlsCertificateKeyFile option specifies the path to the client certificate file or the client private key file. If you need both, you must concatenate the files. To learn more about setting this option, see the Provide Certificate Filepaths section of the TLS guide.
데이터 유형: string
기본값: null
예시:
const tlsCertKeyFileUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsCertificateKeyFile=/path/to/client.pem');클라이언트 인증서 키 파일 암호를 지정하십시오.
The tlsCertificateKeyFilePassword option specifies the password to decrypt the client private key used for TLS connections.
데이터 유형: string
기본값: null
예시:
const tlsCertKeyPasswordUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsCertificateKeyFile=/path/to/client.pem&tlsCertificateKeyFilePassword=iperLuv60');유효하지 않은 인증서를 허용합니다
The tlsAllowInvalidCertificates option specifies whether the driver generates an error when the server's TLS certificate is invalid. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsAllowInvalidCertsUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsAllowInvalidCertificates=true');유효하지 않은 호스트 이름 허용
The tlsAllowInvalidHostnames option specifies whether the driver generates an error when there is a mismatch between the server's hostname and the hostname specified by the TLS certificate. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsAllowInvalidHostnamesUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsAllowInvalidHostnames=true');TLS 제약 조건 완화
The tlsInsecure option relaxes TLS constraints as much as possible, such as allowing invalid certificates or hostname mismatches. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsInsecureUriClient = new MongoClient( 'mongodb://localhost:27017/?tls=true&tlsInsecure=true');TLS 활성화
서버 연결에 TLS를 요구할지 여부를 지정합니다. "mongodb+srv" 체계를 사용하거나 다른 TLS 옵션을 지정하는 경우 이 옵션의 기본값은 true입니다. 그렇지 않으면 기본값은 false입니다.
The ssl option is an alias for the tls option.
데이터 유형: boolean
기본값: false
예시:
const tlsClient = new MongoClient(uri, { tls: true,});CA 파일을 지정하십시오.
The tlsCAFile option specifies the path to a file with either a single or bundle of certificate authorities to trust when making a TLS connection. To learn more about setting this option, see the Provide Certificate Filepaths section of the TLS guide.
데이터 유형: string
기본값: null
예시:
const tlsCaFileClient = new MongoClient(uri, { tls: true, tlsCAFile: '/path/to/ca.pem',});클라이언트 인증서 키 파일을 지정하십시오.
The tlsCertificateKeyFile option specifies the path to the client certificate file or the client private key file. If you need both, you must concatenate the files. To learn more about setting this option, see the Provide Certificate Filepaths section of the TLS guide.
데이터 유형: string
기본값: null
예시:
const tlsCertKeyFileClient = new MongoClient(uri, { tls: true, tlsCertificateKeyFile: '/path/to/client.pem',});클라이언트 인증서 키 파일 암호를 지정하십시오.
The tlsCertificateKeyFilePassword option specifies the password to decrypt the client private key used for TLS connections.
데이터 유형: string
기본값: null
예시:
const tlsCertKeyPasswordClient = new MongoClient(uri, { tls: true, tlsCertificateKeyFile: '/path/to/client.pem', tlsCertificateKeyFilePassword: 'iperLuv60',});유효하지 않은 인증서를 허용합니다
The tlsAllowInvalidCertificates option specifies whether the driver generates an error when the server's TLS certificate is invalid. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsAllowInvalidCertsClient = new MongoClient(uri, { tls: true, tlsAllowInvalidCertificates: true,});유효하지 않은 호스트 이름 허용
The tlsAllowInvalidHostnames option specifies whether the driver generates an error when there is a mismatch between the server's hostname and the hostname specified by the TLS certificate. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsAllowInvalidHostnamesClient = new MongoClient(uri, { tls: true, tlsAllowInvalidHostnames: true,});TLS 제약 조건 완화
The tlsInsecure option relaxes TLS constraints as much as possible, such as allowing invalid certificates or hostname mismatches. Set this option to true for testing purposes only.
데이터 유형: boolean
기본값: false
예시:
const tlsInsecureClient = new MongoClient(uri, { tls: true, tlsInsecure: true,});TLS 옵션에 대한 자세한 내용은 연결에서 TLS 활성화 가이드를 참조하세요.
타임아웃 옵션
ConnectTimeout
시간이 초과하기 전에 드라이버가 서버에 단일 TCP 소켓 연결을 설정하려고 시도하는 시간 길이.
Data Type: non-negative number
기본값: 30000 밀리초
예시:
const connectTimeoutUriClient = new MongoClient( 'mongodb://localhost:27017/?connectTimeoutMS=60000');소켓 타임아웃
운전자 시간이 초과되기 전에 소켓에서 전송 또는 수신을 시도하는 시간입니다. 기본값 은 운영 체제에서 설정하다 .
If a MongoDB process fails with an error or the network connection drops, you might not receive confirmation that the driver closed the corresponding socket. To ensure that the driver closes the socket in these cases, set the socketTimeoutMS option. Select a value for socketTimeoutMS that is two to three times longer than the expected duration of your slowest operation.
Data Type: non-negative number
기본값: 0 (타임아웃 없음)
예시:
const socketTimeoutUriClient = new MongoClient( 'mongodb://localhost:27017/?socketTimeoutMS=60000');ServerSelectionTimeout
드라이버가 시간이 초과되기 전에 서버 선택을 시도하는 시간입니다.
Data Type: non-negative number
기본값: 30000 밀리초
예시:
const serverSelectionTimeoutUriClient = new MongoClient( 'mongodb://localhost:27017/?serverSelectionTimeoutMS=10000');ConnectTimeout
시간이 초과하기 전에 드라이버가 서버에 단일 TCP 소켓 연결을 설정하려고 시도하는 시간 길이.
Data Type: non-negative number
기본값: 30000 밀리초
예시:
const connectTimeoutClient = new MongoClient(uri, { connectTimeoutMS: 60000,});소켓 타임아웃
운전자 시간이 초과되기 전에 소켓에서 전송 또는 수신을 시도하는 시간입니다. 기본값 은 운영 체제에서 설정하다 .
If a MongoDB process fails with an error or the network connection drops, you might not receive confirmation that the driver closed the corresponding socket. To ensure that the driver closes the socket in these cases, set the socketTimeoutMS option. Select a value for socketTimeoutMS that is two to three times longer than the expected duration of your slowest operation.
Data Type: non-negative number
기본값: 0 (타임아웃 없음)
예시:
const socketTimeoutClient = new MongoClient(uri, { socketTimeoutMS: 60000,});ServerSelectionTimeout
드라이버가 시간이 초과되기 전에 서버 선택을 시도하는 시간입니다.
Data Type: non-negative number
기본값: 30000 밀리초
예시:
const serverSelectionTimeoutClient = new MongoClient(uri, { serverSelectionTimeoutMS: 10000,});개별 작업의 서버 실행 시간을 제한하는 방법을 알아보려면 서버 실행 시간 제한 가이드를 참조하세요.
압축 옵션
압축기
서버에 전송되거나 서버에서 수신되는 유선 프로토콜 메시지에 대한 선호 압축 유형(순서 대로). 선택 사항 빌드 시간 종속성으로 "snappy", "zlib", "zstd"를 활성화할 수 있습니다. 드라이버는 서버가 지원하는 이러한 압축 유형 중 첫 번째 것을 사용합니다.
Data Type: comma-separated string
기본값: null
예시:
const compressorsUriClient = new MongoClient( 'mongodb://localhost:27017/?compressors=snappy,zlib,zstd');zlibCompressionLevel
The zlibCompressionLevel option sets the compression level for zlib to use. This option accepts an integer value between -1 and 9:
-1: 기본 압축 수준.0: 압축이 없습니다.1: 속도는 가장 빠르지만 압축률은 가장 낮습니다.9: 압축률은 가장 높지만 속도가 가장 느립니다.
데이터 유형: number between -1 and 9 (inclusive)
기본값: -1
예시:
const zlibLevelUriClient = new MongoClient( 'mongodb://localhost:27017/?compressors=zlib&zlibCompressionLevel=6');압축기
서버에 전송되거나 서버에서 수신되는 유선 프로토콜 메시지에 대한 선호 압축 유형(순서 대로). 선택 사항 빌드 시간 종속성으로 "snappy", "zlib", "zstd"를 활성화할 수 있습니다. 드라이버는 서버가 지원하는 이러한 압축 유형 중 첫 번째 것을 사용합니다.
Data Type: array of string values
기본값: null
예시:
const compressorsClient = new MongoClient(uri, { compressors: ['snappy', 'zlib', 'zstd'],});zlibCompressionLevel
The zlibCompressionLevel option sets the compression level for zlib to use. This option accepts an integer value between -1 and 9:
-1: 기본 압축 수준.0: 압축이 없습니다.1: 속도는 가장 빠르지만 압축률은 가장 낮습니다.9: 압축률은 가장 높지만 속도가 가장 느립니다.
데이터 유형: number between -1 and 9 (inclusive)
기본값: -1
예시:
const zlibLevelClient = new MongoClient(uri, { compressors: ['zlib'], zlibCompressionLevel: 6,});압축에 대한 자세한 내용은 네트워크 트래픽 압축 가이드를 참조하십시오.
연결 풀 옵션
maxPoolSize
드라이버가 연결 풀에서 생성할 수 있는 최대 클라이언트 또는 연결 수입니다. 이 수에는 사용 중인 연결이 포함됩니다.
Data Type: non-negative number
기본값: 100
예시:
const maxPoolSizeUriClient = new MongoClient( 'mongodb://localhost:27017/?maxPoolSize=150');minPoolSize
작업이 발생하지 않는 경우에도 드라이버가 연결 풀에서 생성하고 유지하는 연결 수입니다. 이 카운트에는 사용 중인 연결이 포함됩니다.
Data Type: non-negative number
기본값: 0
예시:
const minPoolSizeUriClient = new MongoClient( 'mongodb://localhost:27017/?minPoolSize=10');MaxConnectionIdleTime
드라이버가 연결을 닫기 전에 연결이 유휴 상태로 지속될 수 있는 시간입니다.
Data Type: non-negative number
기본값: 0 (no limit)
예시:
const maxIdleTimeUriClient = new MongoClient( 'mongodb://localhost:27017/?maxIdleTimeMS=30000');MaxConnecting
The maxConnecting option sets the maximum number of connections the connection pool may establish concurrently.
Data Type: non-negative number
기본값: 2
예시:
const maxConnectingUriClient = new MongoClient( 'mongodb://localhost:27017/?maxConnecting=5');대기열 시간 초과
운전자 시간이 초과되기 전에 서버의 연결 풀 에서 연결을 체크아웃하려고 시도하는 시간입니다.
Data Type: non-negative number
기본값: 0 (타임아웃 없음)
예시:
const waitQueueTimeoutUriClient = new MongoClient( 'mongodb://localhost:27017/?waitQueueTimeoutMS=2000');maxPoolSize
드라이버가 연결 풀에서 생성할 수 있는 최대 클라이언트 또는 연결 수입니다. 이 수에는 사용 중인 연결이 포함됩니다.
Data Type: non-negative number
기본값: 100
예시:
const maxPoolSizeClient = new MongoClient(uri, { maxPoolSize: 150,});minPoolSize
작업이 발생하지 않는 경우에도 드라이버가 연결 풀에서 생성하고 유지하는 연결 수입니다. 이 카운트에는 사용 중인 연결이 포함됩니다.
Data Type: non-negative number
기본값: 0
예시:
const minPoolSizeClient = new MongoClient(uri, { minPoolSize: 10,});MaxConnectionIdleTime
드라이버가 연결을 닫기 전에 연결이 유휴 상태로 지속될 수 있는 시간입니다.
Data Type: non-negative number
기본값: 0 (no limit)
예시:
const maxIdleTimeClient = new MongoClient(uri, { maxIdleTimeMS: 30000,});MaxConnecting
The maxConnecting option sets the maximum number of connections the connection pool may establish concurrently.
Data Type: non-negative number
기본값: 2
예시:
const maxConnectingClient = new MongoClient(uri, { maxConnecting: 5,});대기열 시간 초과
운전자 시간이 초과되기 전에 서버의 연결 풀 에서 연결을 체크아웃하려고 시도하는 시간입니다.
Data Type: non-negative number
기본값: 0 (타임아웃 없음)
예시:
const waitQueueTimeoutClient = new MongoClient(uri, { waitQueueTimeoutMS: 2000,});연결 풀에 대한 자세한 내용은 연결 풀을 사용한 연결 관리 가이드를 참조하세요.
쓰기 고려 옵션
쓰기 고려
쓰기 고려 (write concern) 의 w 구성 요소로, 쓰기 (write) 작업이 지정된 수의 MongoDB 인스턴스로 전파되었음을 확인 요청합니다. 기본값 은 중재자 및 투표 노드 수에 따라 "majority" 또는 1입니다. w 옵션에 대해 자세히 학습하려면 MongoDB Server 매뉴얼에서 쓰기 고려 를 참조하세요.
쓰기 관련 문제를 해결하기 위해 연결 문자열에 다음 옵션을 설정할 수도 있습니다.
journal: 드라이버가 서버가 디스크의 저널 파일에 그룹 커밋할 때까지 기다릴지 여부를 지정합니다.wtimeoutMS: 쓰기 작업에 대한 시간 제한을 지정합니다.
자세한 내용은 MongoDB 서버 설명서의 쓰기 컨선(Write Concern) 섹션을 참조하십시오.
데이터 유형:
woption:numberorstringjournal옵션:booleanwtimeoutMS옵션: 비음수number
기본값:
w옵션:1journaloption: depends on thewriteConcernMajorityJournalDefaultreplica set configuration settingwtimeoutMSoption:0(no timeout)
예시:
const writeConcernUriClient = new MongoClient( 'mongodb://localhost:27017/?w=majority&journal=true&wtimeoutMS=1000');쓰기 고려
The writeConcern option specifies the level of acknowledgement requested from MongoDB for write operations, including the time limit.
자세한 내용은 MongoDB 서버 설명서의 쓰기 컨선(Write Concern) 섹션을 참조하십시오.
The MongoClientOptions type also defines top-level w, wtimeoutMS, and journal options. These top-level options are deprecated. Set the properties on the writeConcern option instead, as shown in the example below.
데이터 유형: WriteConcern or WriteConcernSettings object
기본값: w: 1
예시:
const writeConcernClient = new MongoClient(uri, { writeConcern: { w: 'majority', journal: true, wtimeoutMS: 1000 },});읽기 고려 옵션
읽기 고려 수준
클라이언트의 읽기 고려 (read concern) 수준입니다. 자세한 내용은 MongoDB Server 매뉴얼의 읽기 고려 (read concern) 참조를 참조하세요.
데이터 유형: string
기본값: null
예시:
const readConcernLevelUriClient = new MongoClient( 'mongodb://localhost:27017/?readConcernLevel=majority');읽기 고려 수준
클라이언트의 읽기 고려 (read concern) 수준입니다. 자세한 내용은 MongoDB Server 매뉴얼의 읽기 고려 (read concern) 참조를 참조하세요.
데이터 유형: string
기본값: null
예시:
const readConcernLevelClient = new MongoClient(uri, { readConcernLevel: 'majority',});읽기 기본 설정 옵션
읽기 설정
클라이언트의 기본 읽기 설정 (read preference)입니다. 자세한 내용은 MongoDB Server 수동의 읽기 설정 (read preference)을 참조하세요.
데이터 유형: string
기본값: primary
예시:
const readPreferenceUriClient = new MongoClient( 'mongodb://localhost:27017/?readPreference=secondaryPreferred');readPreferenceTags
The readPreferenceTags option specifies the default read preference tags for the client as comma-separated key:value pairs. This option is valid only if the read preference mode is not primary. The driver uses the order of the tags in the URI as the order for the read preference. To learn more about read preference tags, see tags in the MongoDB Server manual.
Data Type: comma-separated key:value pairs
기본값: null
예시:
const readPreferenceTagsUriClient = new MongoClient( replicaSetUri + '&readPreference=secondaryPreferred&readPreferenceTags=dc:ny,rack:1');최대 보관 기간
최대 비활성 시간(초)은 세컨더리 경험할 수 있고 여전히 서버 선택 대상이 될 수 있는 벽시계 시간으로 가장 긴 복제 지연 나타냅니다. maxStalenessSeconds 에 허용되는 가장 작은 값은 90 초입니다. 이 옵션은 프라이머리가 아닌 읽기 설정 (read preference) 과 함께 사용해야 합니다.
최대값을 적용하지 않으려면 이 옵션을 명시적으로 설정하는 대신 생략하십시오.
데이터 유형: number 크거나 같음 90
기본값: null (최대치 없음)
예시:
const maxStalenessUriClient = new MongoClient( replicaSetUri + '&readPreference=secondaryPreferred&maxStalenessSeconds=120');LocalThreshold
서버 자격에 대한 지연 시간 창 . 서버의 왕복 시간이 가장 빠른 서버의 왕복 시간에 이 값을 더한 것보다 오래 걸리는 경우 해당 서버 선택할 수 없습니다.
Data Type: non-negative number
기본값: 15 밀리초
예시:
const localThresholdUriClient = new MongoClient( 'mongodb://localhost:27017/?localThresholdMS=30');읽기 설정
클라이언트의 기본 읽기 설정 (read preference)입니다. 자세한 내용은 MongoDB Server 수동의 읽기 설정 (read preference)을 참조하세요.
데이터 유형: ReadPreferenceMode or ReadPreference object
기본값: primary
예시:
const readPreferenceClient = new MongoClient(uri, { readPreference: 'secondaryPreferred',});readPreferenceTags
The readPreferenceTags option specifies the default read preference tags for the client. Each tag set is an object that maps tag keys to values. This option is valid only if the read preference mode is not primary. To learn more about read preference tags, see tags in the MongoDB Server manual.
데이터 유형: 태그 문서 배열
기본값: null
예시:
const readPreferenceTagsClient = new MongoClient(replicaSetUri, { readPreference: 'secondaryPreferred', readPreferenceTags: [{ dc: 'ny', rack: '1' }],});최대 보관 기간
최대 비활성 시간(초)은 세컨더리 경험할 수 있고 여전히 서버 선택 대상이 될 수 있는 벽시계 시간으로 가장 긴 복제 지연 나타냅니다. maxStalenessSeconds 에 허용되는 가장 작은 값은 90 초입니다. 이 옵션은 프라이머리가 아닌 읽기 설정 (read preference) 과 함께 사용해야 합니다.
최대값을 적용하지 않으려면 이 옵션을 명시적으로 설정하는 대신 생략하십시오.
데이터 유형: number 크거나 같음 90
기본값: null (최대치 없음)
예시:
const maxStalenessClient = new MongoClient(replicaSetUri, { readPreference: 'secondaryPreferred', maxStalenessSeconds: 120,});LocalThreshold
서버 자격에 대한 지연 시간 창 . 서버의 왕복 시간이 가장 빠른 서버의 왕복 시간에 이 값을 더한 것보다 오래 걸리는 경우 해당 서버 선택할 수 없습니다.
Data Type: non-negative number
기본값: 15 밀리초
예시:
const localThresholdClient = new MongoClient(uri, { localThresholdMS: 30,});인증 옵션
인증 메커니즘
드라이버가 MongoDB Server에 대해 인증하는 메커니즘입니다. 인증 메커니즘을 지정하지 않으면 드라이버는 서버 버전에 따라 SCRAM-SHA-1 또는 SCRAM-SHA-256를 사용합니다.
사용 가능한 인증 메커니즘에 대한 자세한 내용은 인증 메커니즘 가이드를 참조하십시오.
데이터 유형: string
기본값: null (the driver uses SCRAM-SHA-1 or SCRAM-SHA-256 depending on the server version)
예시:
const authMechanismUriClient = new MongoClient( 'mongodb://user:password@localhost:27017/?authSource=admin&authMechanism=SCRAM-SHA-256');인증 메커니즘 속성
The authMechanismProperties option specifies properties for the authentication mechanism set in the authMechanism option, such as the service name for Kerberos (GSSAPI) authentication.
데이터 형식: 쉼표로 구분된 키-값 쌍
기본값: null
예시:
const authMechanismPropertiesUriClient = new MongoClient( 'mongodb://<Kerberos principal>@localhost:27017/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:<service name>');authSource
The authSource option specifies the database that contains the user's credentials.
데이터 유형: string
기본값: null
예시:
const authSourceUriClient = new MongoClient( 'mongodb://user:password@localhost:27017/?authSource=admin');인증 메커니즘
드라이버가 MongoDB Server에 대해 인증하는 메커니즘입니다. 인증 메커니즘을 지정하지 않으면 드라이버는 서버 버전에 따라 SCRAM-SHA-1 또는 SCRAM-SHA-256를 사용합니다.
사용 가능한 인증 메커니즘에 대한 자세한 내용은 인증 메커니즘 가이드를 참조하십시오.
데이터 유형: AuthMechanism
기본값: null (the driver uses SCRAM-SHA-1 or SCRAM-SHA-256 depending on the server version)
예시:
const authMechanismClient = new MongoClient( 'mongodb://user:password@localhost:27017/', { authSource: 'admin', authMechanism: 'SCRAM-SHA-256', });인증 메커니즘 속성
The authMechanismProperties option specifies properties for the authentication mechanism set in the authMechanism option, such as the service name for Kerberos (GSSAPI) authentication.
데이터 유형: AuthMechanismProperties 객체
기본값: null
예시:
const authMechanismPropertiesClient = new MongoClient( 'mongodb://<Kerberos principal>@localhost:27017/', { authMechanism: 'GSSAPI', authMechanismProperties: { SERVICE_NAME: '<service name>', }, });authSource
The authSource option specifies the database that contains the user's credentials.
데이터 유형: string
기본값: null
예시:
const authSourceClient = new MongoClient( 'mongodb://user:password@localhost:27017/', { authSource: 'admin', });서버 모니터링 옵션
하트비트 빈도
서버 모니터링 확인 사이의 간격입니다. 500 밀리초 이상이어야 합니다. 기본값 은 풀링된(멀티 스레드) 모드 에서 10000 ms(10 초), 비풀링된(단일 스레드) 모드 에서 60000 ms(60 초) 입니다.
Node.js 드라이버는 연결 풀을 유지 관리하므로 기본적으로 풀링 모드로 작동합니다.
데이터 유형: number 크거나 같음 500
기본값: 10000 밀리초
예시:
const heartbeatFrequencyUriClient = new MongoClient( 'mongodb://localhost:27017/?heartbeatFrequencyMS=10000');서버 모니터링 모드
The serverMonitoringMode option specifies the monitoring mode that the driver monitors use. When this option is set to auto, the monitoring mode is determined by the environment in which the driver runs. The driver uses polling mode in function-as-a-service (FaaS) environments and the streaming mode in other environments.
데이터 유형: auto, stream 또는 poll
기본값: auto
예시:
const serverMonitoringModeUriClient = new MongoClient( 'mongodb://localhost:27017/?serverMonitoringMode=poll');하트비트 빈도
서버 모니터링 확인 사이의 간격입니다. 500 밀리초 이상이어야 합니다. 기본값 은 풀링된(멀티 스레드) 모드 에서 10000 ms(10 초), 비풀링된(단일 스레드) 모드 에서 60000 ms(60 초) 입니다.
Node.js 드라이버는 연결 풀을 유지 관리하므로 기본적으로 풀링 모드로 작동합니다.
데이터 유형: number 크거나 같음 500
기본값: 10000 밀리초
예시:
const heartbeatFrequencyClient = new MongoClient(uri, { heartbeatFrequencyMS: 10000,});서버 모니터링 모드
The serverMonitoringMode option specifies the monitoring mode that the driver monitors use. When this option is set to auto, the monitoring mode is determined by the environment in which the driver runs. The driver uses polling mode in function-as-a-service (FaaS) environments and the streaming mode in other environments.
데이터 유형: auto, stream 또는 poll
기본값: auto
예시:
const serverMonitoringModeClient = new MongoClient(uri, { serverMonitoringMode: 'poll',});재시도 옵션
읽기 재시도
재시도 가능 읽기를 활성화합니다.
데이터 유형: boolean
기본값: true
예시:
const retryReadsUriClient = new MongoClient( 'mongodb://localhost:27017/?retryReads=false');RetryWrites
재시도 가능 쓰기를 활성화합니다.
데이터 유형: boolean
기본값: true
예시:
const retryWritesUriClient = new MongoClient( 'mongodb://localhost:27017/?retryWrites=false');최대 적응 재시도
The maxAdaptiveRetries option sets the maximum number of retries to attempt when the driver encounters overload errors. Specifying 0 disables adaptive retries. This option requires MongoDB Atlas 9.0 or later.
Data Type: non-negative number
기본값: 2
예시:
const maxAdaptiveRetriesUriClient = new MongoClient( 'mongodb://localhost:27017/?maxAdaptiveRetries=2');과부하 리타겟팅
The enableOverloadRetargeting option specifies whether the driver deprioritizes a server that returns an overload error, reducing the likelihood of retrying on the same overloaded server. This option requires MongoDB Atlas 9.0 or later.
데이터 유형: boolean
기본값: false
예시:
const overloadRetargetingUriClient = new MongoClient( 'mongodb://localhost:27017/?enableOverloadRetargeting=true');읽기 재시도
재시도 가능 읽기를 활성화합니다.
데이터 유형: boolean
기본값: true
예시:
const retryReadsClient = new MongoClient(uri, { retryReads: false,});RetryWrites
재시도 가능 쓰기를 활성화합니다.
데이터 유형: boolean
기본값: true
예시:
const retryWritesClient = new MongoClient(uri, { retryWrites: false,});최대 적응 재시도
The maxAdaptiveRetries option sets the maximum number of retries to attempt when the driver encounters overload errors. Specifying 0 disables adaptive retries. This option requires MongoDB Atlas 9.0 or later.
Data Type: non-negative number
기본값: 2
예시:
const maxAdaptiveRetriesClient = new MongoClient(uri, { maxAdaptiveRetries: 2,});과부하 리타겟팅
The enableOverloadRetargeting option specifies whether the driver deprioritizes a server that returns an overload error, reducing the likelihood of retrying on the same overloaded server. This option requires MongoDB Atlas 9.0 or later.
데이터 유형: boolean
기본값: false
예시:
const overloadRetargetingClient = new MongoClient(uri, { enableOverloadRetargeting: true,});참고
지능형 워크로드 관리(IWM)의 부하 차단
SystemOverloadedError 또는 RetryableError 레이블이 있는 오류로 인해 애플리케이션에서 오류가 발생하거나 애플리케이션 로그에 나타나는 경우, 클러스터에서 Load Shedding이 활성화되어 있고 드라이버가 이를 지원하는 버전으로 업그레이드되지 않았을 수 있습니다. MongoDB Node.js 드라이버를 7.2 버전 이상으로 업그레이드하는 것이 좋습니다. 업그레이드 후에도 이러한 오류가 계속 표시되면 Load Shedding 구성 검토와 같은 서버 사이드 변경을 통해 해결하거나 사용자 지정 오류 처리 또는 클라이언트 사이드 요청 제한 구현과 같은 애플리케이션 사이드 변경을 통해 해결할 수 있습니다. 상황에 따라 애플리케이션 사이드 변경이 더 바람직하거나 필요할 수 있습니다.
Load Shedding은 IWM의 기능으로, 지속적인 과부하 상황에서 초과 작업을 거부하여 서버 부하를 관리하는 데 도움이 됩니다. 이 기능은 MongoDB 9.0 이상에서 사용할 수 있습니다.
IWM 또는 과부시 오류 처리에 대한 자세한 내용은 Atlas 문서의 지능형 워크로드 관리 페이지 또는 과부시 오류 페이지를 참조하십시오.
기타 옵션
애플리케이션 이름
연결 핸드쉐이크의 일부로 드라이버가 클라이언트 메타데이터에 서버에 전달하는 앱 이름입니다. 서버는 연결이 설정되면 이 값을 MongoDB 로그에 인쇄합니다. 이 값은 느린 쿼리 로그 및 프로필 컬렉션에도 기록됩니다.
데이터 유형: string
기본값: null
예시:
const appNameUriClient = new MongoClient( 'mongodb://localhost:27017/?appName=docsExample');로드 밸런싱
운전자 로드 밸런서 에 연결 중인지 여부를 지정합니다. 다음 조건이 모두 충족되는 경우에만 이 속성 true 로 설정하다 수 있습니다.
호스팅하다 이름을 하나만 지정합니다.
복제본 세트 에 연결하지 않습니다.
SrvMaxHosts속성 사용하지 않습니다.DirectConnection속성 사용하지 않습니다.
The Node.js driver supports this option only in the connection string. You cannot set it in a MongoClientOptions object.
데이터 유형: boolean
기본값: false
예시:
const loadBalancedUriClient = new MongoClient( 'mongodb://localhost:27017/?loadBalanced=true');SRVmax 호스트
시드 목록을 처음 채울 때 또는 SRV 폴링 중에 토폴로지에 새 호스트를 추가할 때 무작위로 선택할 수 있는 SRV 결과의 최대 개수입니다.
이 속성 연결 문자열 체계가 ConnectionStringScheme.MongoDBPlusSrv로 설정하다 경우에만 사용할 수 있습니다. 복제본 세트 에 연결할 때는 사용할 수 없습니다.
Data Type: non-negative number
기본값: 0 (제한 없는)
예시:
const srvMaxHostsUriClient = new MongoClient( 'mongodb+srv://cluster.example.mongodb.net/?srvMaxHosts=10');srvServiceName
운전자 시드 목록을 구성하기 위해 검색하는 SRV 리소스 레코드 의 서비스 이름입니다. 운전자 서비스 이름을 사용하여 다음 형식과 일치하는 SRV URI를 생성합니다.
_{srvServiceName}._tcp.{hostname}.{domainname}이 속성 검색 및 폴링에서 SRV 조회에 대한 기본값 서비스 이름을 재정의합니다. 기본값 은 "mongodb"입니다.
이 속성 연결 문자열 체계가 ConnectionStringScheme.MongoDBPlusSrv로 설정하다 경우에만 사용할 수 있습니다. 복제본 세트 에 연결할 때는 사용할 수 없습니다.
데이터 유형: string
기본값: mongodb
예시:
const srvServiceNameUriClient = new MongoClient( 'mongodb+srv://cluster.example.mongodb.net/?srvServiceName=docsExample');자동 선택 패밀리
If you set the autoSelectFamily option to true, the socket attempts to connect to IPv6 and IPv4 addresses until a connection is established. If available, the driver selects the first IPv6 address.
데이터 유형: boolean
기본값: true
예시:
const autoSelectFamilyUriClient = new MongoClient( 'mongodb://localhost:27017/?autoSelectFamily=false');자동 가족 선택 시도 시간 초과
The autoSelectFamilyAttemptTimeout option specifies the amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option. If you set a positive integer less than 10, the driver uses 10 instead.
Data Type: non-negative number
기본값: null
예시:
const autoSelectFamilyAttemptTimeoutUriClient = new MongoClient( 'mongodb://localhost:27017/?autoSelectFamilyAttemptTimeout=300');UTF-8 유효성 검사
The enableUtf8Validation option specifies whether the driver validates UTF-8 characters when it deserializes BSON documents from MongoDB. If you enable validation, the driver throws a BSONError when it reads data that contains invalid UTF-8 characters. Disable UTF-8 validation only as a temporary workaround to query or export data.
UTF-8 문자에 대해 자세히 학습 Wikipedia의 UTF-8 를 참조하세요.
데이터 유형: boolean
기본값: true
예시:
const utf8ValidationUriClient = new MongoClient( 'mongodb://localhost:27017/?enableUtf8Validation=false');SOCKS5 프록시
You can route connections through a SOCKS5 proxy by setting the proxyHost option to the proxy's IPv4 address, IPv6 address, or domain name. The proxyPort option specifies the TCP port number of the proxy server. To authenticate to the proxy server, set the proxyUsername and proxyPassword options. If you omit the proxyPort option, the driver uses 1080. If you set one of the proxyUsername or proxyPassword options, you must set both. To learn more, see Enable SOCKS5 Proxy Support.
데이터 유형:
stringfor theproxyHost,proxyUsername, andproxyPasswordoptionsnon-negative
numberfor theproxyPortoption
기본값: null 네 가지 옵션 모두에 대해
예시:
const proxyUriClient = new MongoClient( 'mongodb://localhost:27017/?proxyHost=proxy.example.com&proxyPort=4040&proxyUsername=proxyUser&proxyPassword=docsExample');애플리케이션 이름
연결 핸드쉐이크의 일부로 드라이버가 클라이언트 메타데이터에 서버에 전달하는 앱 이름입니다. 서버는 연결이 설정되면 이 값을 MongoDB 로그에 인쇄합니다. 이 값은 느린 쿼리 로그 및 프로필 컬렉션에도 기록됩니다.
데이터 유형: string
기본값: null
예시:
const appNameClient = new MongoClient(uri, { appName: 'docsExample',});SRVmax 호스트
시드 목록을 처음 채울 때 또는 SRV 폴링 중에 토폴로지에 새 호스트를 추가할 때 무작위로 선택할 수 있는 SRV 결과의 최대 개수입니다.
이 속성 연결 문자열 체계가 ConnectionStringScheme.MongoDBPlusSrv로 설정하다 경우에만 사용할 수 있습니다. 복제본 세트 에 연결할 때는 사용할 수 없습니다.
Data Type: non-negative number
기본값: 0 (제한 없는)
예시:
const srvMaxHostsClient = new MongoClient( 'mongodb+srv://cluster.example.mongodb.net/', { srvMaxHosts: 10, });srvServiceName
운전자 시드 목록을 구성하기 위해 검색하는 SRV 리소스 레코드 의 서비스 이름입니다. 운전자 서비스 이름을 사용하여 다음 형식과 일치하는 SRV URI를 생성합니다.
_{srvServiceName}._tcp.{hostname}.{domainname}이 속성 검색 및 폴링에서 SRV 조회에 대한 기본값 서비스 이름을 재정의합니다. 기본값 은 "mongodb"입니다.
이 속성 연결 문자열 체계가 ConnectionStringScheme.MongoDBPlusSrv로 설정하다 경우에만 사용할 수 있습니다. 복제본 세트 에 연결할 때는 사용할 수 없습니다.
데이터 유형: string
기본값: mongodb
예시:
const srvServiceNameClient = new MongoClient( 'mongodb+srv://cluster.example.mongodb.net/', { srvServiceName: 'docsExample', });자동 선택 패밀리
If you set the autoSelectFamily option to true, the socket attempts to connect to IPv6 and IPv4 addresses until a connection is established. If available, the driver selects the first IPv6 address.
데이터 유형: boolean
기본값: true
예시:
const autoSelectFamilyClient = new MongoClient(uri, { autoSelectFamily: false,});자동 가족 선택 시도 시간 초과
The autoSelectFamilyAttemptTimeout option specifies the amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option. If you set a positive integer less than 10, the driver uses 10 instead.
Data Type: non-negative number
기본값: null
예시:
const autoSelectFamilyAttemptTimeoutClient = new MongoClient(uri, { autoSelectFamilyAttemptTimeout: 300,});UTF-8 유효성 검사
The enableUtf8Validation option specifies whether the driver validates UTF-8 characters when it deserializes BSON documents from MongoDB. If you enable validation, the driver throws a BSONError when it reads data that contains invalid UTF-8 characters. Disable UTF-8 validation only as a temporary workaround to query or export data.
UTF-8 문자에 대해 자세히 학습 Wikipedia의 UTF-8 를 참조하세요.
데이터 유형: boolean
기본값: true
예시:
const utf8ValidationClient = new MongoClient(uri, { enableUtf8Validation: false,});SOCKS5 프록시
You can route connections through a SOCKS5 proxy by setting the proxyHost option to the proxy's IPv4 address, IPv6 address, or domain name. The proxyPort option specifies the TCP port number of the proxy server. To authenticate to the proxy server, set the proxyUsername and proxyPassword options. If you omit the proxyPort option, the driver uses 1080. If you set one of the proxyUsername or proxyPassword options, you must set both. To learn more, see Enable SOCKS5 Proxy Support.
데이터 유형:
stringfor theproxyHost,proxyUsername, andproxyPasswordoptionsnon-negative
numberfor theproxyPortoption
기본값: null 네 가지 옵션 모두에 대해
예시:
const proxyClient = new MongoClient(uri, { proxyHost: 'proxy.example.com', proxyPort: 4040, proxyUsername: 'proxyUser', proxyPassword: 'docsExample',});런타임 어댑터
(Experimental) The runtimeAdapters option specifies custom implementations of core Node.js APIs. Use this option to run the driver in restricted environments or in alternative runtimes incompatible with Node.js. This option is not supported in a connection string.
데이터 유형: RuntimeAdapters 객체
기본값: null
예시:
const runtimeAdaptersClient = new MongoClient(uri, { runtimeAdapters: { os: { arch: () => 'x64', platform: () => 'linux', release: () => '5.4.0', type: () => 'Linux', }, },});Keep Alive 초기 지연
The keepAliveInitialDelay option specifies the number of milliseconds that the driver waits before initiating a Transmission Control Protocol (TCP) keepalive on a socket. When the driver sends TCP keepalives, it checks whether the connection is active by sending periodic pings to your MongoDB deployment. This functionality works only if your operating system supports the SO_KEEPALIVE socket option. This option is not supported in a connection string.
Driver version 5.3 deprecated the keepAlive option. As of driver version 6.0, the driver always sets keepAlive to true.
경고
방화벽이 킵얼라이브 메시지를 무시하거나 제거하는 경우 제거된 연결을 식별하지 못할 수도 있습니다.
Data Type: non-negative number
기본값: 120000 milliseconds (120 seconds)
추가 정보
사용 가능한 모든 설정을 보려면 MongoClientOptions 를 참조하세요. API 문서.
연결 문자열 옵션에 대한 자세한 내용은 MongoDB 서버 설명서의 연결 문자열 옵션을 참조하십시오.