44
55.. default-domain:: mongodb
66
7+ .. facet::
8+ :name: genre
9+ :values: reference
10+
711.. contents:: On this page
812 :local:
913 :backlinks: none
@@ -24,7 +28,7 @@ Definition
2428
2529 .. note::
2630
27- The view modified by this command does not refer to materialized
31+ The view modified by ``collMod`` does not refer to materialized
2832 views. For discussion of on-demand materialized views, see
2933 :pipeline:`$merge` instead.
3034
3438The command has the following syntax:
3539
3640.. code-block:: javascript
41+ :copyable: false
3742
3843 db.runCommand(
3944 {
@@ -147,11 +152,12 @@ Change Index Properties
147152 change:
148153
149154 .. code-block:: javascript
155+ :copyable: false
150156
151157 db.runCommand( {
152158 collMod: <collection>,
153159 index: {
154- keyPattern: <index_spec> || name: <index_name>,
160+ keyPattern: <index_spec> | name: <index_name>,
155161 expireAfterSeconds: <number>, // Set the TTL expiration threshold
156162 hidden: <boolean>, // Change index visibility in the query planner
157163 prepareUnique: <boolean>, // Reject new duplicate index entries
@@ -273,10 +279,11 @@ Modify Time Series Collections
273279 value:
274280
275281 .. code-block:: javascript
282+ :copyable: false
276283
277284 db.runCommand( {
278285 collMod: <collection>,
279- expireAfterSeconds: <number> || "off"
286+ expireAfterSeconds: <number> | "off"
280287 } )
281288
282289 Set ``expireAfterSeconds`` to ``"off"`` to disable automatic removal,
@@ -293,34 +300,35 @@ Modify Time Series Collections
293300 series collection, you can increase ``timeseries.granularity`` from a shorter unit of time to a longer one:
294301
295302 .. code-block:: javascript
303+ :copyable: false
296304
297- db.runCommand({
305+ db.runCommand( {
298306 collMod: "weather24h",
299- timeseries: { granularity: "seconds" || "minutes" | | "hours" }
300- })
307+ timeseries: { granularity: "seconds" | "minutes" | "hours" }
308+ } )
301309
302- To update the custom bucketing parameters ``bucketRoundingSeconds``
310+ To update the custom bucketing fields ``bucketRoundingSeconds``
303311 and ``bucketMaxSpanSeconds`` instead of ``granularity``, include both
304- custom parameters in the ``collMod`` command and set them to the
312+ custom fields in the ``collMod`` command and set them to the
305313 same value:
306314
307315 .. code-block:: javascript
308316
309- db.runCommand({
317+ db.runCommand( {
310318 collMod: "weather24h",
311319 timeseries: {
312- bucketRoundingSeconds: " 86400" ,
313- bucketMaxSpanSeconds: " 86400"
320+ bucketRoundingSeconds: 86400,
321+ bucketMaxSpanSeconds: 86400
314322 }
315- })
316-
323+ } )
324+
317325 You cannot decrease the granularity interval or the custom bucketing
318326 values.
319327
320328 .. important::
321329
322330 You cannot downgrade below MongoDB 6.3 if any time series
323- collections explicitly specify the custom bucketing parameters
331+ collections explicitly specify the custom bucketing fields
324332 ``bucketMaxSpanSeconds`` and ``bucketRoundingSeconds``. If
325333 possible, convert to the corresponding ``granularity``. If you
326334 cannot, you must drop the collection before downgrading.
@@ -366,6 +374,7 @@ For example, the following command sets the maximum size of a capped collection
366374to 100000 bytes and sets the maximum number of documents in the collection to 500:
367375
368376.. code-block:: javascript
377+ :copyable: false
369378
370379 db.runCommand( {
371380 collMod: <collection>,
@@ -456,19 +465,15 @@ the following privilege to run the ``collMod`` command:
456465 :header-rows: 1
457466
458467 * - Task
459-
460468 - Required Privileges
461469
462470 * - Modify a non-capped collection
463-
464471 - :authaction:`collMod` in the database
465472
466473 * - Modify a view
467-
468474 - :authaction:`collMod` in the database and either:
469475
470476 - no :authaction:`find` on the view to modify, **or**
471-
472477 - both :authaction:`find` on the view to modify and
473478 :authaction:`find` on the source collection/view.
474479
@@ -530,13 +535,13 @@ planner.
530535
531536.. code-block:: javascript
532537
533- db.runCommand({
538+ db.runCommand( {
534539 collMod: "orders",
535540 index: {
536541 keyPattern: { shippedDate: 1 },
537542 hidden: true
538543 }
539- })
544+ } )
540545
541546If successful, the operation returns a document that includes both the
542547old and new value for the changed property:
@@ -548,7 +553,7 @@ old and new value for the changed property:
548553.. note::
549554
550555 If the operation is successful but the ``hidden`` value has not
551- changed (i.e. hiding an already hidden index or unhiding an already
556+ changed (specifically, hiding an already hidden index or unhiding an already
552557 unhidden index), the command omits the ``hidden_old`` and
553558 ``hidden_new`` fields from the output.
554559
@@ -561,7 +566,6 @@ To hide a text index, you must specify the index by ``name`` and not by
561566 - :method:`db.collection.hideIndex()`
562567 - :method:`db.collection.unhideIndex()`
563568
564-
565569Convert an Existing Index to a Unique Index
566570~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
567571
@@ -620,7 +624,7 @@ converting the index:
620624 keyPattern: { type: 1 },
621625 unique: true
622626 }
623- } )
627+ } )
624628
625629The response to this operation varies by driver. You will always
626630receive an error message about the duplicate entries.
@@ -654,4 +658,4 @@ entries:
654658 }
655659
656660To complete the conversion, modify the duplicate entries to remove any
657- conflicts and re-run ``collMod()`` with the ``unique`` option.
661+ conflicts and re-run ``collMod()`` with the ``unique`` option.
0 commit comments