MongoDB とドライバー
説明
バージョン6.2で変更。
db.collection.validate(<documents>)コレクションを検証します。 メソッドは、コレクション データとインデックスをスキャンして正確性を確認し、結果を返します。 出力の詳細については、「 出力の検証 」を参照してください。
バージョン5.0 以降では、
db.collection.validate()メソッドによってコレクション内の不整合も修正できます。インデックスの不一致には、次のものが含まれます。
インデックスはマルチキーですが、マルチキー フィールドはありません。
インデックスには、マルチキーではないフィールドをカバーするmultikeyPathがあります。
インデックスにmultikeyPathsはありませんが、マルチキー ドキュメントは存在します( 3.4 以前にビルドされたインデックスの場合)。
If any inconsistencies are detected by the
db.collection.validate()command, a warning is returned and the repair flag on the index is set totrue.db.collection.validate()also validates any documents that violate the collection's schema validation rules.The
db.collection.validate()method is a wrapper around thevalidatecommand.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
注意
このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
The db.collection.validate() method has the following syntax:
db.collection.validate( { full: <boolean>, // Optional repair: <boolean>, // Optional, added in MongoDB 5.0 checkBSONConformance: <boolean> // Optional, added in MongoDB 6.2 } )
パラメーター
The db.collection.validate() method can take the following optional document parameter with the fields:
フィールド | タイプ | 説明 |
|---|---|---|
ブール値 | 任意。 コマンドがより遅くてより詳細なチェックを実行するか、より高速であるが完全ではないチェックを実行するかを決定するフラグです。
デフォルトは WiredTiger storage engine の場合、ディスク上のデータを検証する前にチェックポイントが強制され、メモリ内のすべてのデータがディスクにフラッシュされるのは | |
ブール値 | 任意。 コマンドが修復を実行するかどうかを決定するフラグです。
デフォルトは 修復はスタンドアロン ノードでのみ実行できます。 この修復により、次の問題が修正されます。
詳細については、 の バージョン 5.0 の新機能。 | |
ブール値 | 任意。
バージョン6.2の新機能。 |
動作
パフォーマンス
The db.collection.validate() method is potentially resource intensive and may impact the performance of your MongoDB instance, particularly on larger data sets.
The db.collection.validate() method obtains an exclusive lock on the collection. This will block all reads and writes on the collection until the operation finishes. When run on a secondary, the operation can block all other operations on that secondary until it finishes.
警告
Validation has exclusive lock requirements that affect performance on primaries and on secondaries that are servicing reads. Consider only running db.collection.validate() on nodes that are not servicing reads or writes.
プライマリへの影響を最小限に抑えるには、クラスター内のデータを保持する(非アービタ)投票ノードの過半数が使用可能であり、レプリケーションラグが大幅にでないようにする必要があります。
To minimize the impact of the validation operation on client applications, run db.collection.validate() on a secondary node that is not servicing read requests. You can convert the current primary node to a secondary node, by running the rs.stepDown() method.
To completely isolate the db.collection.validate() operation from client traffic, choose one of the following options:
レプリカセット ノードを分離するには、ローリング メンテナンス手順に従って一時的にクラスターから一時的に削除します。
データスループット メトリクス
$currentOpコマンドとcurrentOpコマンドには、進行中の操作を検証するためのdataThroughputAverageとdataThroughputLastSecond情報が含まれています。
検証操作のログ メッセージには、 dataThroughputAverageとdataThroughputLastSecondの情報が含まれます。
コレクション検証の改善
MongoDB6.2 以降では、validate コマンドとdb.collection.validate() メソッドは次のようになります。
コレクションをチェックして、 BSON ドキュメントが BSON 仕様に準拠していることを確認します。
時系列コレクションの内部データの不整合をチェックします。
包括的な BSON チェックを可能にする新しいオプション
checkBSONConformanceが追加されました。
例
デフォルトの検証設定(具体的には、 full: false )を使用してコレクション
myCollectionを検証するには次のようにします。db.myCollection.validate() db.myCollection.validate({ }) db.myCollection.validate( { full: false } ) コレクション
myCollectionの完全な検証を実行するには、 full: trueを指定します。db.myCollection.validate( { full: true } ) コレクション
myCollectionを修復するには、修復: trueを指定します。db.myCollection.validate( { repair: true } ) myCollectionで追加の BSON 準拠チェックを実行するには、 checkpointBSONConformance: trueを指定します。db.myCollection.validate( { checkBSONConformance: true } )
出力の詳細については、「 出力の検証 」を参照してください。