Skip to content

Commit

Permalink
DOCS-7373, DOCS-7407 capped collection immutable document size
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-kim committed Mar 14, 2016
1 parent 19f012f commit 205f0c5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 44 deletions.
42 changes: 7 additions & 35 deletions source/core/capped-collections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ collections:
``_id`` Index
~~~~~~~~~~~~~

.. versionchanged:: 2.4

Capped collections have an ``_id`` field and an index on the ``_id``
field by default.

.. _capped-collections-recommendations-and-restrictions:

Restrictions and Recommendations
Expand All @@ -77,33 +75,12 @@ Updates
If you plan to update documents in a capped collection, create an index
so that these update operations do not require a table scan.

With MMAPv1, you can only make in-place updates of documents. If the
update operation causes a document to grow beyond the document's
original size, the update operation will fail.

Replica Sets with MMAPv1 Secondaries
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you update a document in a capped collection to a size smaller than
its original size and a secondary resyncs from the primary, the
secondary will replicate and allocate space based on the current
smaller document size.

If the primary then receives an update which increases the document
back to its original size, the primary will accept the update. However,
for MMAPv1, the secondary will fail with a ``failing update: objects in
a capped ns cannot grow`` error message.
Document Size
~~~~~~~~~~~~~

To prevent this error, create your secondary from a snapshot of one of
the other up-to-date members of the replica set. Follow the
:doc:`tutorial on filesystem snapshots
</tutorial/backup-with-filesystem-snapshots>` to seed your new
secondary.
.. versionchanged:: 3.2

Seeding the secondary with a filesystem snapshot is the only way to
guarantee the primary and secondary binary files are compatible.
|MMS| Backup snapshots are insufficient in this situation since you
need more than the content of the secondary to match the primary.
.. include:: /includes/extracts/capped-collection-immutable-document-size.rst

Document Deletion
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -139,7 +116,7 @@ Create a Capped Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~

You must create capped collections explicitly using the
:method:`~db.createCollection()` method, which is a helper in the
:method:`db.createCollection()` method, which is a helper in the
:program:`mongo` shell for the :dbcommand:`create` command. When
creating a capped collection you must specify the maximum size of the
collection in bytes, which MongoDB will pre-allocate for the collection.
Expand All @@ -166,7 +143,7 @@ collection using the ``max`` field as in the following document:
documents if a collection reaches the maximum size limit before it
reaches the maximum document count.

.. see:: :method:`~db.createCollection()` and :dbcommand:`create`.
.. see:: :method:`db.createCollection()` and :dbcommand:`create`.

.. _capped-collections-options:

Expand Down Expand Up @@ -211,11 +188,6 @@ bytes.

.. include:: /includes/warning-blocking-global.rst

.. versionchanged:: 2.2
Before 2.2, capped collections did not have an index on ``_id``
unless you specified ``autoIndexId`` to the :dbcommand:`create`,
after 2.2 this became the default.

Automatically Remove Data After a Specified Period of Time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
25 changes: 25 additions & 0 deletions source/includes/extracts-capped-collection-document-size.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ref: _capped-collection-immutable-document-size
content: |
If {{write}} changes the document size, the operation will fail.
---
ref: capped-collection-immutable-document-size
source:
file: extracts-capped-collection-document-size.yaml
ref: _capped-collection-immutable-document-size
replacement:
write: "an update or a replacement operation"
---
ref: capped-collection-immutable-document-size-update
source:
file: extracts-capped-collection-document-size.yaml
ref: _capped-collection-immutable-document-size
replacement:
write: "an update operation"
---
ref: capped-collection-immutable-document-size-replace
source:
file: extracts-capped-collection-document-size.yaml
ref: _capped-collection-immutable-document-size
replacement:
write: "a replacement operation"
...
4 changes: 1 addition & 3 deletions source/reference/method/db.collection.replaceOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ document based on the ``replacement`` document. See
Capped Collections
~~~~~~~~~~~~~~~~~~

:method:`~db.collection.replaceOne()` throws a ``WriteError`` if the
replacement document has a larger size in ``bytes`` than the original
document.
.. include:: /includes/extracts/capped-collection-immutable-document-size-replace.rst

.. TBD - need to test more thoroughly to pin down func.
.. Sharded Collections
Expand Down
4 changes: 1 addition & 3 deletions source/reference/method/db.collection.updateMany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ document based on the ``filter`` and ``update`` parameters. See
Capped Collections
~~~~~~~~~~~~~~~~~~

:method:`~db.collection.updateMany()` throws a ``WriteError`` if the
``update`` criteria increases the size of any matching document in a
:term:`capped collection`.
.. include:: /includes/extracts/capped-collection-immutable-document-size-update.rst

.. TBD - need to test more thoroughly to pin down func.
.. Sharded Collections
Expand Down
4 changes: 1 addition & 3 deletions source/reference/method/db.collection.updateOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ document based on the ``filter`` criteria and ``update`` modifications. See
Capped Collection
~~~~~~~~~~~~~~~~~

:method:`~db.collection.updateOne()` throws a ``WriteError`` exception if the
``update`` criteria increases the size of the first matching document in a
:term:`capped collection`.
.. include:: /includes/extracts/capped-collection-immutable-document-size-update.rst

.. TBD - need to test more thoroughly to pin down func.
.. Sharded Collections
Expand Down

0 comments on commit 205f0c5

Please sign in to comment.