diff --git a/source/reference/command/cloneCollectionAsCapped.txt b/source/reference/command/cloneCollectionAsCapped.txt new file mode 100644 index 00000000000..f51a78c19bf --- /dev/null +++ b/source/reference/command/cloneCollectionAsCapped.txt @@ -0,0 +1,38 @@ +======================= +cloneCollectionAsCapped +======================= + +.. default-domain:: mongodb + +.. dbcommand:: cloneCollectionAsCapped + + The :dbcommand:`cloneCollectionAsCapped` command creates a new + :term:`capped collection` from an existing, non-capped collection + within the same database. The original non-capped collection + remains after the operation. + + The command has the following syntax: + + .. code-block:: javascript + + { cloneCollectionAsCapped: , toCollection: , size: } + + The command copies an ``existing collection`` and creates a new + ``capped collection`` with a maximum size specified by the ``capped + size`` in bytes. The name of the new capped collection must be + distinct and cannot be the same as that of the original existing + collection. To replace the original non-capped collection with a + capped collection, use the :dbcommand:`convertToCapped` command. + + During the cloning, the :dbcommand:`cloneCollectionAsCapped` command + exhibit the following behavior: + + - The documents in the original collection will be traversed in + :term:`$natural order ` and loaded into a new + capped collection. + + - If the ``capped size`` specified for the capped collection is + smaller than the size of the original uncapped collection, then + the documents will be aged out of the collection based on + insertion order(First In, First Out). + diff --git a/source/reference/command/convertToCapped.txt b/source/reference/command/convertToCapped.txt index a97c65e4457..d68496e485b 100644 --- a/source/reference/command/convertToCapped.txt +++ b/source/reference/command/convertToCapped.txt @@ -7,7 +7,8 @@ convertToCapped .. dbcommand:: convertToCapped The :dbcommand:`convertToCapped` command converts an existing, - non-capped collection to a :term:`capped collection`. + non-capped collection to a :term:`capped collection` within the same + database. The command has the following syntax: @@ -30,6 +31,14 @@ convertToCapped smaller than the size of the original uncapped collection, then the documents will be aged out of the collection based on insertion order(First In, First Out). + + - The actual conversion process consists of the + :dbcommand:`cloneCollectionAsCapped` command followed by a + :dbcommand:`renameCollection` command. First, the + :dbcommand:`cloneCollectionAsCapped` command creates the capped + collection. Then, the original collection is dropped. Finally, the + :dbcommand:`renameCollection` command renames the new capped + collection to the name of the original collection. .. note::