=====================================
MongoDB\\Database::modifyCollection()
=====================================

.. versionadded:: 1.4

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: singlecol

Definition
----------

.. phpmethod:: MongoDB\Database::modifyCollection()

   Modifies a collection or view according to the specified
   ``$collectionOptions``.

   .. code-block:: php

      function modifyCollection(
          string $collectionName,
          array $collectionOptions,
          array $options = []
      ): array|object

Parameters
----------

``$collectionName`` : string
  The name of the collection or view to modify.

``$collectionOptions`` : array
  Collection or view options to assign.

``$options`` : array
  An array specifying the desired options.

  .. list-table::
     :header-rows: 1
     :widths: 20 20 80

     * - Name
       - Type
       - Description

     * - comment
       - mixed
       - .. include:: /includes/extracts/common-option-comment.rst

         .. include:: /includes/extracts/option-requires-4.4.rst

         .. versionadded:: 1.13

     * - session
       - :php:`MongoDB\Driver\Session <class.mongodb-driver-session>`
       - .. include:: /includes/extracts/common-option-session.rst

     * - typeMap
       - array
       - .. include:: /includes/extracts/database-option-typeMap.rst

         This will be used for the returned command result document.

     * - writeConcern
       - :php:`MongoDB\Driver\WriteConcern <class.mongodb-driver-writeconcern>`
       - .. include:: /includes/extracts/database-option-writeConcern.rst

Return Values
-------------

An array or object with the result document of the :manual:`collMod
</reference/command/collMod>` command.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

Example
-------

The following example changes the expiration time of a TTL collection in the
``test`` database:

.. code-block:: php

   <?php

   $db = (new MongoDB\Client)->test;

   $result = $db->modifyCollection('users', [
       'keyPattern' => ['lastAccess' => 1],
       'expireAfterSeconds' => 1000
   ]);

   var_dump($result);

The output would then resemble:

.. code-block:: none

   object(stdClass)#2779 {
     ["expireAfterSeconds_old"]=>
     int(3)
     ["expireAfterSeconds_new"]=>
     int(1000)
     ["ok"]=>
     float(1)
   }

See Also
--------

- :manual:`collMod </reference/command/collMod>` command reference in the MongoDB
  manual
