Docs 菜单

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.

此命令可用于以下环境中托管的部署:

重要

M0、M2、M5 和 Flex 集群或无服务器实例不支持此命令。有关更多信息,请参阅不支持的命令。

该命令具有以下语法:

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.

size

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

writeConcern

可选。 表达 命令 写关注(write concern) drop的文档。省略以使用默认的写关注(write concern)。

comment

可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:

注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。

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.

此功能会在操作期间保持数据库独占锁。锁定同一数据库的其他操作将被阻止,直到该操作完成。请参阅某些常见客户端操作会采用哪些锁?锁定数据库的操作。