db.collection.getIndexes()
MongoDB とドライバー
このページではmongosh
メソッドがドキュメントされています。 MongoDB ドライバーで同等のメソッドを確認するには、プログラミング言語の対応するページを参照してください。
定義
db.collection.getIndexes()
Returns an array that holds a list of documents that identify and describe the existing indexes on the collection, including hidden indexes and indexes that are currently being built.
You must call
db.collection.getIndexes()
on a collection. For example:db.collection.getIndexes() Change
collection
to the name of the collection for which to return index information.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
注意
このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
動作
Atlas Search インデックス
getIndexes()
does not return information on Atlas Search indexes. For information on Atlas
Search indexes, use $listSearchIndexes
.
クライアントの切断
MongoDB 4.2以降では、 db.collection.getIndexes()
を発行したクライアントが操作の完了前に切断した場合、MongoDB は killOp
を使用して
db.collection.getIndexes()
を終了対象としてマークし 。
レプリカセット ノードの状態の制限
レプリカセット ノードで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.
必要なアクセス権
To run db.collection.getIndexes()
when access control is
enforced, users must have privileges to listIndexes
on the
collection.
The built-in role read
provides the required privileges to
run db.collection.getIndexes()
for the collections in a
database.
出力
db.collection.getIndexes()
returns an array of documents that
hold index information for the collection. For example:
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" }, { "v" : 2, "key" : { "status" : 1 }, "name" : "status_1" }, { "v" : 2, "key" : { "points" : 1 }, "name" : "points_1" } ]
Index information includes the keys and options used to create the
index. The index option hidden
is only available if the value is true
.
For information on the keys and index options, see
db.collection.createIndex()
.