4
4
5
5
.. default-domain:: mongodb
6
6
7
+ .. facet::
8
+ :name: genre
9
+ :values: reference
10
+
7
11
.. contents:: On this page
8
12
:local:
9
13
:backlinks: none
@@ -24,7 +28,7 @@ Definition
24
28
25
29
.. note::
26
30
27
- The view modified by this command does not refer to materialized
31
+ The view modified by ``collMod`` does not refer to materialized
28
32
views. For discussion of on-demand materialized views, see
29
33
:pipeline:`$merge` instead.
30
34
34
38
The command has the following syntax:
35
39
36
40
.. code-block:: javascript
41
+ :copyable: false
37
42
38
43
db.runCommand(
39
44
{
@@ -147,11 +152,12 @@ Change Index Properties
147
152
change:
148
153
149
154
.. code-block:: javascript
155
+ :copyable: false
150
156
151
157
db.runCommand( {
152
158
collMod: <collection>,
153
159
index: {
154
- keyPattern: <index_spec> || name: <index_name>,
160
+ keyPattern: <index_spec> | name: <index_name>,
155
161
expireAfterSeconds: <number>, // Set the TTL expiration threshold
156
162
hidden: <boolean>, // Change index visibility in the query planner
157
163
prepareUnique: <boolean>, // Reject new duplicate index entries
@@ -273,10 +279,11 @@ Modify Time Series Collections
273
279
value:
274
280
275
281
.. code-block:: javascript
282
+ :copyable: false
276
283
277
284
db.runCommand( {
278
285
collMod: <collection>,
279
- expireAfterSeconds: <number> || "off"
286
+ expireAfterSeconds: <number> | "off"
280
287
} )
281
288
282
289
Set ``expireAfterSeconds`` to ``"off"`` to disable automatic removal,
@@ -293,11 +300,12 @@ Modify Time Series Collections
293
300
series collection, you can increase ``timeseries.granularity`` from a shorter unit of time to a longer one:
294
301
295
302
.. code-block:: javascript
303
+ :copyable: false
296
304
297
- db.runCommand({
305
+ db.runCommand( {
298
306
collMod: "weather24h",
299
- timeseries: { granularity: "seconds" || "minutes" | | "hours" }
300
- })
307
+ timeseries: { granularity: "seconds" | "minutes" | "hours" }
308
+ } )
301
309
302
310
To update the custom bucketing parameters ``bucketRoundingSeconds``
303
311
and ``bucketMaxSpanSeconds`` instead of ``granularity``, include both
@@ -306,14 +314,14 @@ Modify Time Series Collections
306
314
307
315
.. code-block:: javascript
308
316
309
- db.runCommand({
317
+ db.runCommand( {
310
318
collMod: "weather24h",
311
319
timeseries: {
312
- bucketRoundingSeconds: " 86400" ,
313
- bucketMaxSpanSeconds: " 86400"
320
+ bucketRoundingSeconds: 86400,
321
+ bucketMaxSpanSeconds: 86400
314
322
}
315
- })
316
-
323
+ } )
324
+
317
325
You cannot decrease the granularity interval or the custom bucketing
318
326
values.
319
327
@@ -366,6 +374,7 @@ For example, the following command sets the maximum size of a capped collection
366
374
to 100000 bytes and sets the maximum number of documents in the collection to 500:
367
375
368
376
.. code-block:: javascript
377
+ :copyable: false
369
378
370
379
db.runCommand( {
371
380
collMod: <collection>,
@@ -456,19 +465,15 @@ the following privilege to run the ``collMod`` command:
456
465
:header-rows: 1
457
466
458
467
* - Task
459
-
460
468
- Required Privileges
461
469
462
470
* - Modify a non-capped collection
463
-
464
471
- :authaction:`collMod` in the database
465
472
466
473
* - Modify a view
467
-
468
474
- :authaction:`collMod` in the database and either:
469
475
470
476
- no :authaction:`find` on the view to modify, **or**
471
-
472
477
- both :authaction:`find` on the view to modify and
473
478
:authaction:`find` on the source collection/view.
474
479
@@ -530,13 +535,13 @@ planner.
530
535
531
536
.. code-block:: javascript
532
537
533
- db.runCommand({
538
+ db.runCommand( {
534
539
collMod: "orders",
535
540
index: {
536
541
keyPattern: { shippedDate: 1 },
537
542
hidden: true
538
543
}
539
- })
544
+ } )
540
545
541
546
If successful, the operation returns a document that includes both the
542
547
old and new value for the changed property:
@@ -548,7 +553,7 @@ old and new value for the changed property:
548
553
.. note::
549
554
550
555
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
552
557
unhidden index), the command omits the ``hidden_old`` and
553
558
``hidden_new`` fields from the output.
554
559
@@ -561,7 +566,6 @@ To hide a text index, you must specify the index by ``name`` and not by
561
566
- :method:`db.collection.hideIndex()`
562
567
- :method:`db.collection.unhideIndex()`
563
568
564
-
565
569
Convert an Existing Index to a Unique Index
566
570
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
567
571
@@ -620,7 +624,7 @@ converting the index:
620
624
keyPattern: { type: 1 },
621
625
unique: true
622
626
}
623
- } )
627
+ } )
624
628
625
629
The response to this operation varies by driver. You will always
626
630
receive an error message about the duplicate entries.
@@ -654,4 +658,4 @@ entries:
654
658
}
655
659
656
660
To 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