Docs Menu

listIndexes

listIndexes

Returns information about the indexes on the specified collection, including hidden indexes and indexes that are currently being built. Returned index information includes the keys and options used to create the index. You can optionally set the batch size for the first batch of results.

mongosh에서 이 명령을 db.collection.getIndexes() 헬퍼 메서드를 통해서도 실행할 수 있습니다.

헬퍼 메서드는 mongosh 사용자에게 편리하지만 데이터베이스 명령과 동일한 수준의 정보를 반환하지 못할 수 있습니다. 편의가 필요하지 않거나 추가 리턴 필드가 필요한 경우 데이터베이스 명령을 사용합니다.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.

명령은 다음과 같은 구문을 가집니다:

db.runCommand (
{
listIndexes: "<collection-name>",
cursor: { batchSize: <int> },
comment: <any>
}
)

이 명령은 다음 필드를 사용합니다.

필드
유형
설명

listIndexes

문자열

컬렉션의 이름입니다.

cursor.batchSize

integer

Optional. Specifies the cursor batch size.

comment

any

선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.

댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다.

listIndexes 명령에 설정된 모든 주석은 listIndexes 커서에서 실행되는 후속 getMore 명령에 의해 상속됩니다.

If access control is enforced, the built-in read role provides the required privileges to run listIndexes for the collections in a database.

listIndexes does not return information on Atlas Search indexes. Instead, use $listSearchIndexes.

MongoDB 4.2부터 listIndexes를 발급한 클라이언트가 작업이 완료되기 전에 연결을 끊는 경우, MongoDB는 listIndexes를 사용하여 를killOp을 종료로 표시합니다.

복제본 세트 노드에서 실행하는 경우 listIndexes 작업을 수행하려면 해당 노드가 PRIMARY 또는 SECONDARY 상태에 있어야 합니다. 노드가 STARTUP2와 같은 다른 상태에 있으면 작업 오류가 발생합니다.

MongoDB 6.3, 6.0.5 및 5.0.16부터 wildcardProjection 필드는 제출된 형식으로 인덱스 프로젝션을 저장합니다. 이전 버전의 서버에서는 프로젝션을 정규화된 형태로 저장했을 수 있습니다.

The server uses the index the same way, but you may notice a difference in the output of the listIndexes and db.collection.getIndexes() commands.

listIndexes.cursor

A result set returned in the batch size specified by your cursor. Each document in the batch output contains the following fields:

필드
유형
설명

id

integer

A 64-bit integer. If zero, there are no more batches of information. If non-zero, a cursor ID, usable in a getMore command to get the next batch of index information.

ns

문자열

The database and collection name in the following format: <database-name>.<collection-name>

firstBatch

문서

Index information includes the keys and options used to create the index. The index option hidden is only present if the value is true.

다음을 사용하세요. getMore to retrieve additional results as needed.

listIndexes.ok

The return value for the command. A value of 1 indicates success.

This example lists indexes for the contacts collection without specifying the cursor batch size.

1db.runCommand (
2 {
3 listIndexes: "contacts"
4 }
5)
1{
2 cursor: {
3 id: Long("0"),
4 ns: 'test.contacts',
5 firstBatch: [
6 { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' },
7 { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' }
8 ]
9 },
10 ok: 1
11}

This example lists indexes for the contacts collection, and specifies a cursor batch size of 1.

1db.runCommand (
2 {
3 listIndexes: "contacts", cursor: { batchSize: 1 }
4 }
5)
1{
2 cursor: {
3 id: Long("4809221676960028307"),
4 ns: 'test.contacts',
5 firstBatch: [ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' } ]
6 },
7 ok: 1
8}

This example uses getMore to retrieve additional result batches from the contacts collection.

1db.runCommand(
2 {
3 getMore: Long("4809221676960028307"), collection: "contacts"
4 }
5)
1{
2 cursor: {
3 nextBatch: [ { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' } ],
4 id: Long("0"),
5 ns: 'test.contacts'
6 },
7 ok: 1
8}