Docs Menu
Docs Home
/ / /
PHP 라이브러리 매뉴얼
/

Stable API

이 페이지의 내용

  • 개요
  • stable API활성화
  • stable API구성
  • API 문서

참고

Stable API 기능을 사용하려면 MongoDB Server 5.0 이상이 필요합니다.

이 가이드에서는 stable API MongoDB deployment에 연결할 때 호환성을 지정하는 방법을 배울 수 있습니다.

Stable API 기능 은 서버 가 지정한 API 버전과 호환되는 동작으로 작업을 실행 하도록 강제합니다. 라이브러리나 서버 버전을 업데이트 하면 API 버전이 변경되어 이러한 작업의 동작 방식이 변경될 수 있습니다. Stable API 를 사용하면 서버 의 일관적인 응답이 보장되고 애플리케이션 에 장기적인 API 안정성이 제공됩니다.

다음 섹션에서는 클라이언트를 위해 stable API 를 활성화하고 MongoDB 사용자 지정하는 방법을 설명합니다. 지원하는 명령 목록을 포함하여 에 대한 자세한 stable API stable API 내용은 MongoDB Server 매뉴얼에서 를 참조하세요.

stable API 를 활성화하려면 다음 단계를 수행하세요.

  1. MongoDB\Driver\ServerApi 객체 를 생성하고 사용하려는 Stable API 버전을 전달합니다. 현재 라이브러리는 버전 1 만 지원합니다.

  2. MongoDB\Client 객체 를 생성합니다. driverOptions 매개변수의 경우 serverApi 옵션이 포함된 배열 을 전달합니다. 이 옵션을 이전 단계에서 만든 MongoDB\Driver\ServerApi 객체 로 설정합니다.

다음 코드 예시에서는 stable API 버전 1을 지정하는 방법을 보여줍니다.

$uri = "mongodb://<hostname>:<port>";
$driverOptions = ['serverApi' => new MongoDB\Driver\ServerApi('1')];
$client = new MongoDB\Client($uri, [], $driverOptions);

참고

지정된 API 버전으로 MongoDB\Client 인스턴스 를 만든 후에는 클라이언트 로 실행 하는 모든 명령이 지정된 버전을 사용합니다. 두 개 이상의 Stable API 버전을 사용하여 명령을 실행 해야 하는 경우 새 MongoDB\Client 인스턴스 만듭니다.

MongoDB\Driver\ServerApi 생성자는 다음과 같은 선택적 매개변수도 허용합니다. 이러한 매개변수를 사용하여 Stable API 의 동작을 사용자 지정할 수 있습니다.

Parameter
설명
strict
Optional. When true, if you call a command that isn't part of the declared API version, the server raises an exception.

Default: null. If this parameter is null, the server applies its default value of false.
deprecationErrors
Optional. When true, if you call a command that is deprecated in the declared API version, the server raises an exception.

Default: null. If this parameter is null, the server applies its default value of false.

다음 코드 예시에서는 MongoDB\Driver\ServerApi 객체를 구성할 때 이러한 매개변수를 사용하는 방법을 보여줍니다.

$uri = "mongodb://<hostname>:<port>";
$serverApi = new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true);
$driverOptions = ['serverApi' => $serverApi];
$client = new MongoDB\Client($uri, [], $driverOptions);

MongoDB\Client 클래스에 대한 자세한 내용은 다음 PHP 라이브러리 API 문서를 참조하세요.

  • MongoDB\Client

MongoDB\Driver\ServerApi 클래스에 대한 자세한 내용은 다음 PHP 확장 API 문서를 참조하세요.

돌아가기

TLS(전송 계층 보안) 구성