정의
cursor.readPref(mode, tagSet, hedgeOptions)중요
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) 모드 중 하나: | |
문서 배열 | ||
문서 | 선택 사항. 헤지된 읽기( hedged read) 사용 여부를 지정하는 문서입니다.
헤지된 읽기 (hedged read)는 샤딩된 클러스터에 사용할 수 있습니다. 헤지된 읽기 (hedged read)를 사용하려면 반드시 읽기 설정 (read preference) |
readPref() does not support the Read Preference maxStalenessSeconds option for read preference.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
예시
읽기 설정 (read preference) 모드 지정
다음 작업은 읽기 설정 모드 를 사용하여 읽기 대상을 세컨더리 멤버로 지정합니다.
db.collection.find({ }).readPref( "secondary")
읽기 설정 (read preference) 태그 세트 지정
특정 태그가 있는 세컨더리를 대상으로 하려면 mode 및 tagSet 배열을 모두 포함합니다.
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는 적격 세컨더리를 사용합니다.
자세한 내용 은 태그 일치 순서를 참조하세요.
헤지된 읽기(hedged read) 지정
샤딩된 클러스터의 경우 프라이머리가 아닌 읽기 설정(read preference)에 대해 헤지된 읽기(hedged read)를 활성화할 수 있습니다. 헤지된 읽기를 사용하려면 mongos에 헤지된 읽기에 대한 enabled support(기본값)가 있어야 하며primary 이외의 읽기 기본 설정에서 헤지된 읽기 사용을 활성화해야 합니다.
헤지된 읽기를 사용하여 샤딩된 클러스터의 세컨더리를 대상으로 하려면 다음 예와 같이 모드와 hedgeOptions를 모두 포함해야 합니다.
태그 세트 없이
db.collection.find({ }).readPref( "secondary", // mode null, // tag set { enabled: true } // hedge options ) 태그 세트 포함
db.collection.find({ }).readPref( "secondary", // mode [ { "datacenter": "B" }, { } ], // tag set { enabled: true } // hedge options )