Docs Menu

cloneCollectionAsCapped

cloneCollectionAsCapped

The cloneCollectionAsCapped command creates a new 上限付きコレクション from an existing, non-capped collection within the same database. The operation does not affect the original non-capped collection.

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

このコマンドは、M0、M2、M5、および Flex クラスターまたはサーバーレス インスタンスではサポートされていません。詳細については、「 サポートされていないコマンド 」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

db.runCommand(
{
cloneCollectionAsCapped: <existing collection>,
toCollection: <capped collection>,
size: <capped size>,
writeConcern: <document>,
comment: <any>
}
)

このコマンドは、次のフィールドを使用します。

フィールド
説明

cloneCollectionAsCapped

The name of the existing collection to copy.

toCollection

The name of the new capped collection to create.

The name of the new capped collection must be distinct and cannot be the same as that of the original existing collection.

サイズ

The maximum size,in bytes, for the capped collection.

writeConcern

任意。 コマンドの drop書込み保証( write concern ) を表すドキュメント。デフォルトの書込み保証を使用する場合は省略します。

comment

任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。

コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。

The command copies an existing collection and creates a new capped collection with a maximum size specified by the capped size in bytes.

To replace the original non-capped collection with a capped collection, use the convertToCapped command.

If the capped size is less than the size of the source collection, then not all documents in the source collection will exist in the destination capped collection.

これにより、操作中はデータベースの排他ロックが保持されます。同じデータベースをロックする他の操作は、操作が完了するまでブロックされます。データベースをロックする操作の場合、「一般的なクライアント操作によって取得されるロック」を参照してください。