重要
mongosh メソッド
This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.
データベースコマンドについては、 collModコマンドを使用して設定されたindex.hiddenコレクション オプションを参照してください。
MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
定義
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- 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 のバージョン
構文
db.collection.unhideIndex(<index>)
パラメーター
The db.collection.unhideIndex() method takes the following parameter:
Parameter | タイプ | 説明 |
|---|---|---|
| 文字列またはドキュメント | クエリ プランナーから再表示するインデックスを指定します。 インデックスは、インデックス名またはインデックス仕様ドキュメントによって指定できます。 インデックス名またはインデックス仕様ドキュメントを見つけるには、 テキストインデックスの非表示を解除するには、インデックス名を指定します。 |
The db.collection.unhideIndex() is a mongosh shell wrapper for the collMod command.
動作
インデックスの変更により統計がリセットされる
非表示インデックスを再表示すると、その$indexStatsがリセットされます。
No-op
すでに非表示になっていないインデックスを再表示しても、インデックスには影響しません。 ただし、操作では空の oplog エントリが生成されます。
必要なアクセス権
配置で認証/承認が強制される場合は、コレクションのデータベースに対してcollMod特権が必要です。
組み込みロール dbAdmin は必要な特権を提供します。
例
次の例では、既存のインデックスを再表示します。
まず、 db.collection.createIndex()を使用して非表示のインデックスを作成します。
db.restaurants.createIndex( { borough: 1, ratings: 1 }, { hidden: true } );
確認するには、 restaurantsコレクションでdb.collection.getIndexes()を実行します。
db.restaurants.getIndexes();
この操作では、次の情報が返されます。
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" }, { "v" : 2, "key" : { "borough" : 1, "ratings" : 1 }, "name" : "borough_1_ratings_1", "hidden" : true } ]
インデックス オプションhiddenは、値がtrueの場合にのみ返されます。
To unhide the index, you can specify either the index key specification document or the index name to the db.collection.unhideIndex() method. The following specifies the index name:
db.restaurants.unhideIndex( "borough_1_ratings_1" );
確認するには、 restaurantsコレクションでdb.collection.getIndexes()を実行します。
db.restaurants.getIndexes()
この操作では、次の情報が返されます。
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" }, { "v" : 2, "key" : { "borough" : 1, "ratings" : 1 }, "name" : "borough_1_ratings_1" } ]
インデックス オプションhiddenは、値がtrueの場合にのみ フィールドが返されるため、 borough_1_ratings_1インデックスの一部として表示されなくなりました。