cloneCollectionAsCapped

Definition

  • cloneCollectionAsCapped
  • The cloneCollectionAsCapped command creates a newcapped collection from an existing, non-capped collectionwithin the same database. The operation does not affect theoriginal non-capped collection.

The command has the following syntax:

  1. { cloneCollectionAsCapped: <existing collection>, toCollection: <capped collection>, size: <capped size>, writeConcern: <document>}

The command takes the following fields:

FieldDescriptioncloneCollectionAsCappedThe name of the existing collection to copy.toCollectionThe name of the new capped collection to create.

The name of the new capped collection must bedistinct and cannot be the same as that of the original existingcollection.sizeThe maximum size,in bytes, for the capped collection.writeConcernOptional. A document expressing the write concern of the drop command.Omit to use the default write concern.

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

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

Behavior

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 destinationcapped collection.

This holds a database exclusive lock for the duration of the operation.Other operations which lock the same database will be blocked until theoperation completes. See What locks are taken by some common client operations? foroperations that lock the database.