AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

db.コレクション.unideIndex()(mongoshメソッド)

重要

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 ドライバーのドキュメント」を参照してください。

db.collection.unhideIndex()

クエリ プランナーから既存のインデックスを再表示します。 非表示が解除されると、インデックスはすぐに使用できるようになります。

このメソッドは、次の環境でホストされている配置で使用できます。

  • 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
タイプ
説明

index

文字列またはドキュメント

クエリ プランナーから再表示するインデックスを指定します。 インデックスは、インデックス名またはインデックス仕様ドキュメントによって指定できます。

インデックス名またはインデックス仕様ドキュメントを見つけるには、 db.collection.getIndexes()メソッドを使用できます。

テキストインデックスの非表示を解除するには、インデックス名を指定します。

The db.collection.unhideIndex() is a mongosh shell wrapper for the collMod command.

非表示インデックスを再表示すると、その$indexStatsがリセットされます。

すでに非表示になっていないインデックスを再表示しても、インデックスには影響しません。 ただし、操作では空の 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インデックスの一部として表示されなくなりました。