문서 메뉴
문서 홈
/ / /
Laravel MongoDB
/ /

연결 옵션

이 페이지의 내용

  • 개요
  • 연결 및 인증 옵션
  • 연결 및 인증 옵션 추가
  • 옵션 설명
  • 드라이버 연결 옵션

이 가이드에서는 연결, 인증 및 드라이버 옵션에 대해 알아보고 Laravel 애플리케이션의 데이터베이스 연결 구성에서 이를 지정하는 방법을 알아봅니다. 연결 옵션은 데이터베이스 연결을 관리하는 MongoDB PHP 라이브러리로 전달됩니다.

MongoDB PHP 라이브러리에 대해 자세히 알아보려면 MongoDB PHP 라이브러리 문서를 참조하세요.

이 가이드에서는 다음과 같은 주제를 다룹니다.

다음 섹션에서 구성 파일에 일반적인 연결 및 인증 옵션을 추가하는 방법을 알아보세요.

다음 방법 중 하나를 사용하여 Laravel 웹 애플리케이션의 config/database.php 구성 파일에서 연결 또는 인증 옵션을 지정할 수 있습니다.

  • 설정과 값을 options 배열 항목에 배열 항목으로 추가합니다.

  • dsn 배열 항목에 지정된 연결 string 에 설정과 값을 쿼리 string 매개 변수로 추가합니다.

options 배열에서 옵션을 지정하려면 다음 예와 같이 해당 이름과 값을 배열 항목으로 추가합니다.

'connections' => [
'mongodb' => [
'dsn' => 'mongodb+srv://mongodb0.example.com/',
'driver' => 'mongodb',
'database' => 'sample_mflix',
'options' => [
'appName' => 'myLaravelApp',
'compressors' => 'zlib',
'zlibCompressionLevel' => 7,
],
],
],

연결 string 에서 옵션을 매개 변수로 지정하려면 다음 쿼리 string 구문 형식을 사용합니다.

  • 물음표 문자 ? 를 추가하여 호스트 정보를 매개변수와 구분합니다.

  • 옵션을 <option>=<value> 형식으로 지정하여 추가합니다.

  • 각 옵션과 값 쌍 사이에 앰퍼샌드 문자 & 를 삽입하여 구분합니다.

다음 설정 예제에서는 연결 string 매개변수 구문을 보여줍니다.

'dsn' => 'mongodb+srv://mongodb0.example.com/?appName=myLaravelApp&compressors=zlib',

다음 표에서는 연결 및 인증 옵션 목록과 해당 기본값에 대해 설명합니다.

옵션 이름
허용되는 값
기본값
설명
앱 이름
문자열
none
Specifies the application name that the MongoDB PHP Library sends the MongoDB deployment as part of the handshake.
Specifying appName can help you identify activities related to that application in the server logs.
authMechanism
문자열
none
사용할 인증 메커니즘을 지정합니다. 이 옵션을 지정하지 않으면 드라이버는 기본 인증 메커니즘을 사용합니다. 자세한 내용은 MongoDB Server 매뉴얼의 인증 을 참조하세요.
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.
압축기
쉼표로 구분된 문자열 목록
none
지정된 순서대로 MongoDB와 애플리케이션 간에 전달되는 네트워크 데이터의 양을 줄이기 위해 MongoDB PHP 라이브러리가 사용하는 데이터 압축기를 지정합니다.
connectTimeoutMS
음수가 아닌 정수
10000 (10초)
서버에 연결을 시도할 때 각 기본 TCP 스트림에 전달되는 연결 제한 시간(밀리초)을 지정합니다.
directConnection
부울
false
클러스터의 모든 서버를 검색하여 연결하는 대신 단일 호스트에 직접 연결할지 여부를 지정합니다. 이 설정에 대해 자세히 알아보려면 연결 가이드의 직접 연결 을 참조하세요.
heartbeatFrequencyMS
다음보다 크거나 같은 정수 500
10000 (10초)
각 모니터링 스레드가 서버 검사를 수행하는 사이에 대기하는 시간(밀리초)을 지정합니다.
일지
부울
false
작업이 온디스크 저널로 전파되었음을 확인 요청합니다.
localThresholdMS
음수가 아닌 정수
15
Specifies the 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 no latency window, so only the server with the lowest average round-trip time is eligible.
maxIdleTimeMS
음수가 아닌 정수
0
Specifies the 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.
최대 보관 기간
-1, 또는 다음보다 크거나 같은 정수 90
-1
Specifies the maximum lag, in seconds, behind the primary node that a secondary node can be considered for the given operation.
This option's value must be at least 90, or the operation raises an error. A value of -1 means there is no maximum lag.
maxPoolSize
음수가 아닌 정수
10
Specifies the maximum number of connections that the MongoDB PHP Library 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
음수가 아닌 정수
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.
readConcernLevel
문자열
none
MongoDB PHP 라이브러리에서 수행하는 작업에 대한 기본 읽기 고려를 지정합니다. 자세한 내용은 MongoDB Server 매뉴얼의 읽기 고려 를 참조하세요.
읽기 설정
문자열
primary
MongoDB PHP 라이브러리가 읽기 작업을 복제본 세트 멤버로 라우팅하는 방법을 지정합니다. 자세한 내용은 MongoDB Server 매뉴얼의 읽기 설정 을 참조하세요.
readPreferenceTags
쉼표로 구분된 키-값 쌍 목록
none
작업에 고려할 복제본 세트 멤버를 지정합니다. 이 키의 각 인스턴스는 별도의 태그 세트입니다. 드라이버는 각 태그가 있는 하나 이상의 서버를 찾을 때까지 각 태그 세트를 확인합니다.
복제본 세트
문자열
none
MongoDB PHP 라이브러리가 연결되는 복제본 세트의 이름을 지정합니다.
retryReads
부울
true
작업이 실패할 경우 MongoDB PHP 라이브러리가 읽기 작업을 다시 시도할지 여부를 지정합니다.
serverSelectionTimeoutMS
음수가 아닌 정수
30000 (30초)
시간이 초과되기 전에 MongoDB PHP 라이브러리가 작업을 위한 서버를 선택하기 위해 기다리는 시간(밀리초)을 지정합니다.
TLS
부울
false
Specifies the TLS configuration for the MongoDB PHP Library to use in its connections with the server.
By default, TLS is off.
tlsAllowInvalidCertificates
부울
false
Specifies whether the MongoDB PHP Library returns an error if the server presents an invalid certificate.
We recommend setting this option to true only in testing environments to avoid creating security vulnerabilities in your application.
tlsCAFile
문자열
설명 참조
Specifies the path to the certificate authority (CA) file that the MongoDB PHP Library 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 MongoDB PHP Library presents to the server to verify its identity.
If you do not set this option, the MongoDB PHP Library does not attempt to verify its identity with the server.
tlsInsecure
부울
false
Specifies whether the MongoDB PHP Library returns an error if the server presents an invalid certificate.
We recommend setting this option to true only in testing environments to avoid creating security vulnerabilities in your application.
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
음수가 아닌 정수
시간 초과 없음
쓰기 고려의 시간 제한을 밀리초 단위로 지정합니다. 제한 시간 내에 작업이 요청된 레벨로 전파되지 않으면 MongoDB PHP 라이브러리에서 오류를 발생시킵니다.
zlibCompressionLevel
-1에서 9 사이의 정수(포괄적)
-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.

연결 옵션의 전체 목록을 보려면 MongoDB Server 매뉴얼의 연결 문자열 가이드에서 연결 string 옵션 섹션을 참조하세요. 페이지 오른쪽에 있는 Select your language 드롭다운 메뉴에서 PHP 을 선택합니다.

드라이버 옵션은 Laravel 애플리케이션과 MongoDB 간의 연결 및 모든 작업을 관리하는 MongoDB PHP 라이브러리의 동작을 수정합니다.

Laravel 웹 애플리케이션의 config/database.php 구성 파일에서 드라이버 옵션을 지정할 수 있습니다. 드라이버 옵션을 추가하려면 다음 예와 같이 driverOptions 배열 항목에 설정과 값을 배열 항목으로 추가합니다.

'connections' => [
'mongodb' => [
'dsn' => 'mongodb+srv://mongodb0.example.com/',
'driver' => 'mongodb',
'database' => 'sample_mflix',
'driverOptions' => [
'serverApi' => 1,
'allow_invalid_hostname' => false,
],
],
]

드라이버 옵션 목록은 MongoDB PHP 라이브러리 문서의 $driverOptions: 배열 섹션을 참조하세요.

돌아가기

연결 가이드

다음

TLS 사용 및 구성