AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

Stable API

참고

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 를 활성화하려면 다음 단계를 수행하세요.

  1. mongocxx::options::server_api 객체 를 생성하고 Stable API 버전을 지정합니다. mongocxx::options::server_api::version 열거형 에 정의된 Stable API 버전을 사용해야 합니다. 현재 운전자 는 버전 1 (k_version_1)만 지원합니다.

  2. mongocxx::options::client 객체 를 생성합니다. 이 객체 의 server_api_opts 필드 를 이전 단계에서 만든 server_api 객체 로 설정합니다.

  3. mongocxx::client 객체 를 생성하고 mongocxx::uri 객체 와 이전 단계에서 생성한 mongocxx::options::client 객체 를 전달합니다.

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

#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/client.hpp>
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 인스턴스 만듭니다.

다음 표에서는 server_api_options 클래스의 속성을 설명합니다. 이러한 속성을 사용하여 Stable API 의 동작을 사용자 지정할 수 있습니다.

옵션 이름
설명

strict

선택 사항. true로 설정된 경우 선언된 API 버전의 일부가 아닌 명령을 호출하면 드라이버에서 예외가 발생합니다.

기본값: false

deprecation_errors

선택 사항. true로 설정된 경우 선언된 API 버전에서 더 이상 사용되지 않는 명령을 호출하면 드라이버에서 예외가 발생합니다.

기본값: false

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

#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/client.hpp>
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);
}

C++ 운전자 에서 Stable API 를 사용하는 방법에 대한 자세한 내용은 다음 API 설명서를 참조하세요.

이 페이지 평가하기