
executeReadWriteCommand 함수를 사용하여 읽기/쓰기 명령을 처리할 때, command 객체를 생성할 때 사용하는 속성은 다음과 같습니다.
- operationType: 읽기/쓰기 명령의 종류를 지정합니다. (e.g. read, write)
- request: 읽기/쓰기 명령을 포함하는 객체를 지정합니다.
- readPreference: 읽기 명령의 읽기 선호도(Preference)를 지정합니다.
- writeConcern: 쓰기 명령의 쓰기 우선 순위(Concern)를 지정합니다.
이 속성을 설정하는 방법은 다음과 같습니다.
1. operationType을 설정합니다. 예를 들어, read 명령을 처리하려면 operationType을 "read"로 설정합니다.
2. request를 설정합니다. 예를 들어, 특정 컬렉션의 데이터를 읽으려면 request에 컬렉션 이름과 필드 이름을 포함합니다.
3. readPreference을 설정합니다. 예를 들어, 읽기 명령의 읽기 선호도는 Primary 또는 Secondary로 설정할 수 있습니다.
4. writeConcern을 설정합니다. 예를 들어, 쓰기 명령의 쓰기 우선 순위는 Acknowledged 또는 W1로 설정할 수 있습니다.
예를 들어, 다음 코드는 읽기 명령을 처리하는 예입니다.
#hostingforum.kr
cpp
auto command = BSONObjBuilder().append("operationType", "read")
.append("request", BSONObjBuilder().append("find", "mycollection").append("filter", BSONObj()).done())
.append("readPreference", "primary")
.append("writeConcern", "acknowledged")
.done();
driver->executeReadWriteCommand(command);
이 코드는 "mycollection" 컬렉션의 모든 데이터를 읽는 읽기 명령을 처리합니다. 읽기 선호도는 Primary로 설정되어 있습니다. 쓰기 우선 순위는 Acknowledged로 설정되어 있습니다.
2025-07-11 10:08