참고
Stable API 기능을 사용하려면 MongoDB Server 5.0 이상이 필요합니다.
개요
이 가이드에서는 stable API MongoDB deployment에 연결할 때 호환성을 지정하는 방법을 배울 수 있습니다.
stable API 기능은 지정한 API 버전과 호환되는 동작으로 서버가 작업을 실행하도록 합니다. 드라이버나 서버를 업데이트하면 API 버전이 변경되어 이러한 작업의 동작 방식이 변경될 수 있습니다. stable API 를 사용하면 서버의 일관된 응답이 보장되고 애플리케이션에 장기적인 API 안정성이 제공됩니다.
The following sections describe how you can enable and customize Stable API for your MongoDB client. For more information about the Stable API, including a list of the commands it supports, see Stable API in the MongoDB Server manual.
stable API활성화
stable API 를 활성화하려면 다음 단계를 수행하세요.
mongocxx::options::server_api객체 를 생성하고 Stable API 버전을 지정합니다.mongocxx::options::server_api::version열거형 에 정의된 Stable API 버전을 사용해야 합니다. 현재 운전자 는 버전 1 (k_version_1)만 지원합니다.mongocxx::options::client객체 를 생성합니다. 이 객체 의server_api_opts필드 를 이전 단계에서 만든server_api객체 로 설정합니다.mongocxx::client객체 를 생성하고mongocxx::uri객체 와 이전 단계에서 생성한mongocxx::options::client객체 를 전달합니다.
다음 코드 예시에서는 stable API 버전 1을 지정하는 방법을 보여줍니다.
int main() { mongocxx::instance instance; mongocxx::uri uri("mongodb://<hostname>:<port>"); mongocxx::options::server_api server_api_options(mongocxx::options::server_api::version::k_version_1); mongocxx::options::client client_options; client_options.server_api_opts(server_api_options); mongocxx::client client(uri, client_options); }
참고
지정된 API 버전으로 mongocxx::client 인스턴스 를 만든 후에는 클라이언트 로 실행 하는 모든 명령이 지정된 버전을 사용합니다. 두 개 이상의 Stable API 버전을 사용하여 명령을 실행 해야 하는 경우 새 mongocxx::client 인스턴스 만듭니다.
stable API구성
다음 표에서는 server_api_options 클래스의 속성을 설명합니다. 이러한 속성을 사용하여 Stable API 의 동작을 사용자 지정할 수 있습니다.
옵션 이름 | 설명 |
|---|---|
strict | 선택 사항. |
deprecation_errors | 선택 사항. |
다음 코드 예시에서는 ServerApi 객체를 구성할 때 이러한 매개변수를 사용하는 방법을 보여줍니다.
int main() { mongocxx::instance instance; mongocxx::uri uri("mongodb://<hostname>:<port>"); mongocxx::options::server_api server_api_options(mongocxx::options::server_api::version::k_version_1); server_api_options.strict(true); server_api_options.deprecation_errors(true); mongocxx::options::client client_options; client_options.server_api_opts(server_api_options); mongocxx::client client(uri, client_options); }
API 문서
C++ 운전자 에서 Stable API 를 사용하는 방법에 대한 자세한 내용은 다음 API 설명서를 참조하세요.