MongoDB とドライバー
定義
db.collection.getIndexes()コレクションの既存のインデックス( 隠しインデックス や現在構築中のインデックスを含む)を識別して説明するドキュメントのリストを含む配列を返します。
You must call
db.collection.getIndexes()on a collection. For example:db.collection.getIndexes() collectionを、インデックス情報を返すコレクションの名前に変更します。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- 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 のバージョン
動作
MongoDB Search インデックス
getIndexes() does not return information on MongoDB Search indexes. For information on Atlas Search indexes, use $listSearchIndexes.
クライアントの切断
If the client that issued db.collection.getIndexes() disconnects before the operation completes, MongoDB marks db.collection.getIndexes() for termination using 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.
必要なアクセス権
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() コレクションのインデックス情報を保持するドキュメントの配列を返します。以下に例を挙げます。
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" }, { "v" : 2, "key" : { "status" : 1 }, "name" : "status_1" }, { "v" : 2, "key" : { "points" : 1 }, "name" : "points_1" } ]
インデックス情報には、インデックスの作成に使用されるキーとオプションが含まれます。 インデックス オプションhiddenは、値がtrueの場合にのみ使用できます。
キーとインデックスのオプションの詳細については、db.collection.createIndex() を参照してください。