정의
cursor.readPref(mode, tagSet)중요
Mongo쉬 방법
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.
Append
readPref()to a cursor to control how the client routes the query to members of the replica set.참고
You must apply
readPref()to the cursor before retrieving any documents from the database.
매개변수
Parameter | 유형 | 설명 |
|---|---|---|
문자열 | 다음 읽기 설정 (read preference) 모드 중 하나: | |
문서 배열 |
readPref() does not support the Read Preference maxStalenessSeconds option for read preference.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
참고
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
예시
읽기 설정 (read preference) 모드 지정
다음 작업은 읽기 설정 모드 를 사용하여 읽기 대상을 세컨더리 멤버로 지정합니다.
db.collection.find({ }).readPref( "secondary")
읽기 설정 (read preference) 태그 세트 지정
To target secondaries with specific tags, include both the mode and the tagSet array:
db.collection.find({ }).readPref( "secondary", [ { "datacenter": "B" }, // First, try matching by the datacenter tag { "region": "West"}, // If not found, then try matching by the region tag { } // If not found, then use the empty document to match all eligible members ] )
세컨더리 선택 프로세스에서 MongoDB는 datacenter: "B" 태그가 있는 세컨더리 멤버를 먼저 찾으려고 합니다.
발견되면 MongoDB는 적격 세컨더리를
datacenter: "B"태그가 있는 세컨더리로 제한하고 나머지 태그를 무시합니다.아무것도 발견되지 않으면 MongoDB는
"region": "West"태그를 사용하여 세컨더리 멤버를 찾으려고 시도합니다.발견되면 MongoDB는 적격 세컨더리를
"region": "West"태그가 있는 세컨더리로 제한합니다.아무것도 발견되지 않으면 MongoDB는 적격 세컨더리를 사용합니다.
자세한 내용 은 태그 일치 순서를 참조하세요.