cursor.returnKey()
정의
cursor.returnKey()
중요
Mongo쉬 방법
이는
mongosh
메서드입니다. 이는Node.js
또는 기타 프로그래밍 언어별 드라이버 메서드에 대한 설명서가 아닙니다.
대부분의 경우
mongosh
메서드는 레거시mongo
shell 메서드와 동일한 방식으로 작동합니다. 그러나 일부 레거시 메서드는mongosh
에서 사용할 수 없습니다.레거시
mongo
셸 문서는 해당 MongoDB 서버 릴리스 문서를 참조하세요.MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 문서를 참조하세요.
팁
$meta
supports the keyword"indexKey"
to return index key metadata if an index is used. The use of{ $meta: "indexKey" }
is preferred overcursor.returnKey()
.문서가 아닌 인덱스 키를 반환하도록 커서를 수정합니다.
cursor.returnKey()
의 형식은 다음과 같습니다.cursor.returnKey() 반환합니다: The cursor that returnKey()
is attached to with a modified result set. This allows for additional cursor modifiers to be chained.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
행동
If the query does not use an index to perform the read operation, the cursor returns empty documents.
예시
The restaurants
collection contains documents with the following schema:
{ "_id" : ObjectId("564f3a35b385149fc7e3fab9"), "address" : { "building" : "2780", "coord" : [ -73.98241999999999, 40.579505 ], "street" : "Stillwell Avenue", "zipcode" : "11224" }, "borough" : "Brooklyn", "cuisine" : "American ", "grades" : [ { "date" : ISODate("2014-06-10T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2013-06-05T00:00:00Z"), "grade" : "A", "score" : 7 } ], "name" : "Riviera Caterer", "restaurant_id" : "40356018" }
The collection has two indexes in addition to the default _id
index:
{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "guidebook.restaurant" }, { "v" : 1, "key" : { "cuisine" : 1 }, "name" : "cuisine_1", "ns" : "guidebook.restaurant" }, { "v" : 1, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "name_text", "ns" : "guidebook.restaurant", "weights" : { "name" : 1 }, "default_language" : "english", "language_override" : "language", "textIndexVersion" : 3 }
The following code uses the cursor.returnKey()
method to return
only the indexed fields used for executing the query:
var csr = db.restaurant.find( { "cuisine" : "Japanese" } ) csr.returnKey()
This returns the following:
{ "cuisine" : "Japanese" } { "cuisine" : "Japanese" } { "cuisine" : "Japanese" } { "cuisine" : "Japanese" } ...