定義
reIndexバージョン 6.0 から非推奨。
Attempting to run the
reIndexcommand writes a warning message to the log.Tip
In
mongosh, this command can also be run through thedb.collection.reIndex()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.The
reIndexcommand drops all indexes on a collection and recreates them. This operation may be expensive for collections that have a large amount of data and/or a large number of indexes.警告
reIndexmay only be run on standalone instances.For most users, the
reIndexcommand is unnecessary.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
重要
このコマンドは、MongoDB Atlas クラスターではサポートされていません。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { reIndex: <collection> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | 説明 |
|---|---|
reIndex | リインデックスするコレクションの名前。 |
動作
MongoDB5.0 以降の場合、reIndex はスタンドアロンインスタンスでのみ実行できます。
リソースのロック
reIndex はコレクションに対して排他的ロック(W)を取得し、完了するまでコレクションに対する他の操作をブロックします。
MongoDB でのロックの詳細については、「FAQ: 同時実行性」を参照してください。
Tip
MongoDB でのインデックス操作の動作の詳細については、「 入力されたコレクションでのインデックス ビルド 」を参照してください。