
MongoDBDriverReadConcern::isDefault 메서드는 디폴트 읽기 우선순위가 설정되어 있는지 여부를 반환합니다. 디폴트 읽기 우선순위를 설정하는 방법은 다음과 같습니다.
1. MongoDB 드라이버의 버전이 4.0 이상인 경우, `MongoClientOptions` 객체의 `readConcern` 속성을 설정합니다. 예를 들어, `MongoClientOptions` 객체를 생성하고 `readConcern` 속성을 `ReadConcern::LOCAL`로 설정하는 방법입니다.
#hostingforum.kr
php
$clientOptions = new MongoClientOptions();
$clientOptions->readConcern = ReadConcern::LOCAL;
2. MongoDB 드라이버의 버전이 3.x인 경우, `MongoClientOptions` 객체의 `readPreference` 속성을 설정합니다. 예를 들어, `MongoClientOptions` 객체를 생성하고 `readPreference` 속성을 `ReadPreference::LOCAL`로 설정하는 방법입니다.
#hostingforum.kr
php
$clientOptions = new MongoClientOptions();
$clientOptions->readPreference = ReadPreference::LOCAL;
디폴트 읽기 우선순위가 설정되어 있는 경우, 읽기 우선순위는 디폴트로 설정됩니다. 디폴트 읽기 우선순위가 설정되어 있지 않은 경우, 읽기 우선순위를 변경하는 방법은 위에서 설명한 방법을 사용합니다.
읽기 우선순위를 변경하는 방법은 다음과 같습니다.
1. `MongoCollection` 객체의 `readConcern` 메서드를 사용하여 읽기 우선순위를 변경합니다. 예를 들어, `MongoCollection` 객체를 생성하고 `readConcern` 메서드를 호출하여 읽기 우선순위를 `ReadConcern::LOCAL`로 변경하는 방법입니다.
#hostingforum.kr
php
$collection = $client->selectCollection($databaseName, $collectionName);
$collection->readConcern(ReadConcern::LOCAL);
2. `MongoCollection` 객체의 `readPreference` 메서드를 사용하여 읽기 우선순위를 변경합니다. 예를 들어, `MongoCollection` 객체를 생성하고 `readPreference` 메서드를 호출하여 읽기 우선순위를 `ReadPreference::LOCAL`로 변경하는 방법입니다.
#hostingforum.kr
php
$collection = $client->selectCollection($databaseName, $collectionName);
$collection->readPreference(ReadPreference::LOCAL);
읽기 우선순위를 변경한 후, `MongoClientOptions` 객체의 `readConcern` 또는 `readPreference` 속성을 다시 설정하여 디폴트 읽기 우선순위를 변경할 수 있습니다.
2025-06-26 14:03