Skip to content

DOCS-1044 collMod updated for 2.4 ability to update TTL collection expiration times #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions source/reference/command/collMod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ collMod

.. index:: document; space allocation
.. index:: usePowerOf2Sizes
.. _usePowerOf2Sizes:
.. collflag:: usePowerOf2Sizes

The :collflag:`usePowerOf2Sizes` flag changes the method that
Expand All @@ -41,7 +42,7 @@ collMod
with :collflag:`usePowerOf2Sizes` set, :program:`mongod`
will allocate records in full megabytes by rounding up to
the nearest megabyte.

:collflag:`usePowerOf2Sizes` is useful for collections where you
will be inserting and deleting large numbers of documents to
ensure that MongoDB will effectively use space on disk.
Expand All @@ -62,6 +63,7 @@ collMod

db.runCommand( { collMod: "products", "usePowerOf2Sizes": false })


.. warning::
.. versionchanged:: 2.2.1
:collflag:`usePowerOf2Sizes` now
Expand All @@ -74,10 +76,49 @@ collMod
as a result of document growth, and *does not* affect
existing allocations.

.. note::
.. index:: expireAfterSeconds
.. collflag:: index

The :collflag:`index` flag changes the expiration time of a
:doc:`TTL Collection </tutorial/expire-data>`.

Specify the key and new expiration time with a document of the form:

.. code-block:: javascript

{keyPattern: <index_spec>, expireAfterSeconds: <seconds> }

where ``<index_spec>`` is an existing index in the collection and
``seconds`` is the number of seconds to subtract from the current
time.

.. example::

To update the expiration value for a collection
named ``sessions`` indexed on a ``lastAccess`` field from 30
minutes to 60 minutes, use the following operation:

.. code-block:: javascript

db.runCommand({collMod: "sessions",
index: {keyPattern: {lastAccess:1},
expireAfterSeconds: 3600}})

Which will return the document:

.. code-block:: javascript

{ "expireAfterSeconds_old" : 1800, "expireAfterSeconds_new" : 3600, "ok" : 1 }

On success a document with fields ``expireAfterSeconds_old``
and ``expireAfterSeconds_new`` set to the respective
values is returned.

:collflag:`usePowerOf2Sizes` has no effect on
:term:`capped collections <capped collection>`.
On failure, a document is returned with
``no expireAfterSeconds field to update``
if there is no existing ``expireAfterSeconds`` field or
``cannot find index { **key**: 1.0 } for ns **namespace**``
if the specified ``keyPattern`` does not exist.

.. Commenting out the following after DOCS-717, it does take
a lock but its to cover a very small metadata change.
Expand Down