|
| 1 | +======================= |
| 2 | +cloneCollectionAsCapped |
| 3 | +======================= |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +.. dbcommand:: cloneCollectionAsCapped |
| 8 | + |
| 9 | + The :dbcommand:`cloneCollectionAsCapped` command creates a new |
| 10 | + :term:`capped collection` from an existing, non-capped collection |
| 11 | + within the same database. The original non-capped collection |
| 12 | + remains after the operation. |
| 13 | + |
| 14 | + The command has the following syntax: |
| 15 | + |
| 16 | + .. code-block:: javascript |
| 17 | + |
| 18 | + { cloneCollectionAsCapped: <existing collection>, toCollection: <capped collection>, size: <capped size> } |
| 19 | + |
| 20 | + The command copies an ``existing collection`` and creates a new |
| 21 | + ``capped collection`` with a maximum size specified by the ``capped |
| 22 | + size`` in bytes. The name of the new capped collection must be |
| 23 | + distinct and cannot be the same as that of the original existing |
| 24 | + collection. To replace the original non-capped collection with a |
| 25 | + capped collection, use the :dbcommand:`convertToCapped` command. |
| 26 | + |
| 27 | + During the cloning, the :dbcommand:`cloneCollectionAsCapped` command |
| 28 | + exhibit the following behavior: |
| 29 | + |
| 30 | + - The documents in the original collection will be traversed in |
| 31 | + :term:`$natural order <natural order>` and loaded into a new |
| 32 | + capped collection. |
| 33 | + |
| 34 | + - If the ``capped size`` specified for the capped collection is |
| 35 | + smaller than the size of the original uncapped collection, then |
| 36 | + the documents will be aged out of the collection based on |
| 37 | + insertion order(First In, First Out). |
| 38 | + |
0 commit comments