-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
2.6.txt
2531 lines (1843 loc) · 85.1 KB
/
2.6.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
:orphan:
========================================================
Release Notes for MongoDB 2.6 (Development Series 2.5.x)
========================================================
.. default-domain:: mongodb
MongoDB 2.6 is currently in development, as part of the 2.5
development release series. While 2.5-series releases are currently
available, these versions of MongoDB are for **testing only and
not for production use**.
This document will eventually contain the full release notes for
MongoDB 2.6; before its release this document covers the 2.5
development series as a work-in-progress.
.. contents:: See the :doc:`full index of this page <2.6-changes>` for
a complete list of changes included in 2.6 (Development
Series 2.5.x).
:backlinks: none
:local:
:depth: 2
Downloading
-----------
You can download the current 2.5 development release on the `downloads
page`_ in the :guilabel:`Development Release (Unstable)`
section. There are no distribution packages for development releases,
but you can use the binaries provided for testing purposes. See
:doc:`/tutorial/install-mongodb-on-linux`,
:doc:`/tutorial/install-mongodb-on-windows`, or
:doc:`/tutorial/install-mongodb-on-os-x` for the basic installation
process.
.. _`downloads page`: http://www.mongodb.org/downloads
Compatibility Changes
---------------------
.. important:: The MongoDB 2.5-series, which will become MongoDB 2.6,
is for testing and development **only**. All identifiers, names,
interfaces are subject to change. Do **not** use a MongoDB 2.5
release in production situations.
SNMP Enterprise Identifier Changed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. DOCS-1696
In 2.5.1, the IANA enterprise identifier for MongoDB changed from
37601 to 34601. Users of SNMP monitoring must modify their SNMP
configuration (i.e. MIB) accordingly.
Default ``bind_ip`` for RPM and DEB Packages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the packages provided by 10gen for MongoDB in RPM (Red Hat, CentOS,
Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and
derivatives,) the default :setting:`bind_ip` value attaches MongoDB
components to the localhost interface *only*. These packages set this
default in the default configuration file
(i.e. ``/etc/mongodb.conf``.)
If you use one of these packages and have *not* modified the default
``/etc/mongodb.conf`` file, you will need to set :setting:`bind_ip`
before or during the upgrade.
There is no default ``bind_ip`` setting in any other 10gen distributions
of MongoDB.
``isMaster`` Comand includes Wire Protocol Versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 2.5.0
In order to support changes to the wire protocol both now and in the
future, the output of :dbcommand:`isMaster` now contains two new
fields that report the earliest version of the wire protocol that this
:program:`mongod` instance supports and the highest version of the
wire protocol that this :program:`mongo` instance supports. See
:data:`~isMaster.minWireVersion` and :data:`~isMaster.maxWireVersion`
for more information.
Replica Set Vote Configuration Validation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 2.5.3
MongoDB now deprecates giving any :term:`replica set` member more than
a single vote. During configuration,
:data:`local.system.replset.members[n].votes` should only have a value
of 1 for voting members and 0 for non-voting members. MongoDB treats
values other than 1 or 0 as a value of 1 and produces a warning message.
.. _agg-helper-incompatibility:
Behavior of ``aggregate()`` Method in the ``mongo`` Shell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionchanged:: 2.5.3
.. the text of this message will improve and become more clear before
2.6 whenwe remove mention of 2.5-series releases.
The :method:`db.collection.aggregate()` helper now :ref:`returns a
cursor <rn-2.6-aggregation-cursor>`. As a result, you cannot use the
:method:`~db.collection.aggregate()` method from a 2.5.3 (or later)
version of the :program:`mongo` shell while connected to 2.4 (and
earlier) versions of MongoDB.
To perform aggregation on earlier versions of MongoDB, use either a
previous version of the :program:`mongo` shell or if using the 2.5.3
(or later) version of the :program:`mongo` shell, run the
:dbcommand:`aggregate` command, not the
:method:`db.collection.aggregate()` helper, without specifying the
``cursor`` option.
.. TODO DOCS-1948 Uncomment when this feature is complete
MongoDB Refuses to Insert Documents that Cannot be Indexed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In 2.5.3, MongoDB will *not* insert documents into collections if
the content of an indexed field exceeds the :limit:`Maximum Index
Key Length <Index Key>` and return an error. In previous versions of
MongoDB, such documents were inserted but not indexed.
.. _authentication-incompatibility:
Authentication and Authorization Incompatibility
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. important::
For authentication/authorization, the 2.5.3 release does not
offer an automatic upgrade process to go from version 2.4 model for
user credentials and privileges to the 2.5.3 model. However, version
2.5.4 **will** provide an automatic upgrade process.
MongoDB 2.5.3 does not offer an automatic upgrade process to go from
version 2.4 model :doc:`user privilege documents
</reference/privilege-documents>` to the :ref:`2.5.3. model
<user-defined-roles>`.
In order to *test* your existing database with the :ref:`MongoDB 2.5.3
authentication/authorization <user-defined-roles>`, you must remove all
the users from the ``system.users`` collection in the ``admin``
database and create new users with the new user privilege model. One
option is to delete all the users while running with
:option:`authorization <--auth>` disabled, and create the first user
with the role { role: "root", db: "admin" } using the
:method:`db.addUser` helper in the :program:`mongo` shell.
Version 2.5.3 is for testing and development **only**.
``$mod`` Query Operator Enforces Strict Syntax
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The :query:`$mod` operator now only accepts an array with exactly two
elements, and errors when passed an array with fewer or more elements.
In previous versions, if passed an array with one element, the
:query:`$mod` operator uses ``0`` as the second element, and if passed
an array with more than two elements, the :query:`$mod` ignores all but
the first two elements. Previous versions do return an error when
passed an empty array.
See :ref:`mod-not-enough-elements` and :ref:`mod-too-many-elements` for
details.
Changes
-------
.. important:: The MongoDB 2.5-series, which will become MongoDB 2.6,
is for testing and development **only**. All identifiers, names,
interfaces are subject to change. Do **not** use a MongoDB 2.5
release in production situations.
Aggregation Pipeline Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. _aggregation-method-change:
``db.collection.aggregation()`` Accepts Second Parameter
````````````````````````````````````````````````````````
In the 2.5.3 version of the :program:`mongo` shell, the
:method:`db.collection.aggregate()` helper can now accept as a second
parameter a document of options:
.. code-block:: javascript
db.collection.aggregate( [ <pipeline> ], { options } )
The second parameter is *optional*.
The updated :method:`db.collection.aggregate()` helper supports legacy
syntax and accepts the pipeline stages as separate arguments. For
example,
.. code-block:: javascript
db.collection.aggregate( { $match: ... }, { $group: ...} )
However, if you do not specify the ``<pipeline>`` in an array, you
cannot specify options.
.. seealso:: :ref:`agg-helper-incompatibility`
``$out`` Stage to Write Data to a Collection
````````````````````````````````````````````
.. versionadded:: 2.5.2
The aggregation pipeline adds a new stage named :pipeline:`$out` that
writes the result of the pipeline operation to an output collection and
returns an empty result set. In version 2.5.3 of the :program:`mongo`
shell, because the :method:`db.collection.aggregate()` method returns a
cursor, specifying an :pipeline:`$out` stage returns an empty cursor.
See the :doc:`$out documentation </reference/operator/aggregation/out>`
for more information.
.. _rn-2.6-aggregation-cursor:
Aggregation Operations Now Return Cursors
`````````````````````````````````````````
.. There's a few other edits in the content below to make our statements stronger.
.. DOCS-1835
The :method:`db.collection.aggregate()` helper in the :program:`mongo`
shell now returns a cursor. By returning a cursor,
aggregation pipelines can return result sets of any size. In previous
versions, the result of an aggregation operation could be no larger
than 16 megabytes.
To perform aggregation on older servers, use either a previous version
of the :program:`mongo` shell or if using the 2.5.3 :program:`mongo`
shell, run the :dbcommand:`aggregate` command, not the
:method:`db.collection.aggregate()` helper, without specifying the
``cursor`` option.
Cursors returned from aggregation only supports cursor methods that
operate on evaluated cursors (i.e. cursors whose first batch has been
retrieved), such as the following methods:
.. hlist::
:columns: 2
* :method:`cursor.hasNext()`
* :method:`cursor.next()`
* :method:`cursor.toArray()`
* :method:`cursor.forEach()`
* :method:`cursor.map()`
* :method:`cursor.objsLeftInBatch()`
* :method:`cursor.itcount()`
* :method:`cursor.pretty()`
.. include:: /includes/important-uses-new-aggregate-helper.rst
The following example returns a cursor from the aggregation operation:
.. code-block:: javascript
var results = db.records.aggregate(
[
{ $project : { name: 1, email: 1, _id: 0 } },
{ $sort : { name: 1 } }
]
)
Like the cursor returned from :method:`db.collection.find()`, in the
:program:`mongo` shell, if the cursor returned from the
:method:`db.collection.aggregate()` is not assigned to a variable using
the ``var`` keyword, then the cursor is automatically iterated up to 20
times. See :doc:`/core/cursors` for cursor behavior in the
:program:`mongo` shell and :doc:`/tutorial/iterate-a-cursor` for
handling cursors in the :program:`mongo` shell.
To specify an *initial* batch size for the cursor, set the option (e.g.
``cursor: { batchSize: <num> }``) in the :ref:`second parameter
<aggregation-method-change>` of the :method:`db.collection.aggregate()`
method. A ``batchSize`` of ``0`` means an empty first batch and is
useful if you want to quickly get back a cursor or a failure message
without doing significant server-side work, as in the following example:
.. code-block:: javascript
var results = db.records.aggregate(
[
{ $project : { name: 1, email: 1, _id: 0 } },
{ $sort : { name: 1 } }
],
{
cursor: { batchSize: 0 }
}
)
The :dbcommand:`aggregate` command may also return a cursor rather than
a result document. To return a cursor object, specify the ``cursor``
option. You can also specify an optional initial batch size to the
command. Using the :dbcommand:`aggregate` command to return a cursor is
a low-level operation, intended for authors of drivers. Most users
should use the :method:`db.collection.aggregate()` helper provided in
the :program:`mongo` shell or in their driver.
The following command returns a document that can be used to
instantiate an object.
.. code-block:: javascript
db.runCommand(
{ aggregate: "records",
pipeline: [
{ $project: { name: 1, email: 1, _id: 0 } },
{ $sort: { name: 1 } }
],
cursor: { }
}
)
To specify an *initial* batch size, specify the ``batchSize`` in the
``cursor`` field, as in the following example:
.. code-block:: javascript
db.runCommand(
{ aggregate: "records",
pipeline: [
{ $project: { name: 1, email: 1, _id: 0 } },
{ $sort: { name: 1 } }
],
cursor: { batchSize: 0 }
}
)
The ``{batchSize: 0 }`` document specifies the size of the *initial*
batch size only. Specify subsequent batch sizes to :ref:`OP_GET_MORE
<wire-op-get-more>` operations as with other MongoDB cursors. A
``batchSize`` of ``0`` means an empty first batch and is useful if you
want to quickly get back a cursor or failure message, without doing
significant server-side work.
Improved Sorting
````````````````
.. versionadded:: 2.5.2
The :pipeline:`$sort` and :pipeline:`$group` stages now use a more
efficient sorting system within the :program:`mongod` process. This
improves performance for sorting operations that cannot rely on an
index or that exceed the maximum memory use limit, see
:limit:`Aggregation Sort Operation` for more information.
For large sort operations these "external sort" operations can write
data to the ``_tmp`` sub-directory in the :setting:`dbpath` directory.
To enable external sort, specify the ``allowDiskUsage`` option as the
:ref:`second parameter <aggregation-method-change>` to the
:method:`db.collection.aggregate()` helper.
.. include:: /includes/important-uses-new-aggregate-helper.rst
.. code-block:: javascript
var results = db.records.aggregate(
[
{ $project : { name: 1, email: 1, _id: 0 } },
{ $sort : { name : 1 } }
],
{
allowDiskUsage: true
}
)
For the :dbcommand:`aggregate` command, add the new ``allowDiskUsage``
argument to the :dbcommand:`aggregate` command, as in the following
prototype:
.. code-block:: javascript
{
aggregate: "<collection>",
pipeline: [<pipeline>],
allowDiskUsage: <boolean>
}
``$redact`` Stage to Provide Filtering for Field-Level Access Control
`````````````````````````````````````````````````````````````````````
.. include:: /includes/important-uses-new-aggregate-helper.rst
.. pipeline:: $redact
.. versionadded:: 2.5.2
Provides a method to restrict the content of a returned document on
a per-field level.
.. example::
Given a collection with the following document in a ``test``
collection:
.. code-block:: javascript
{ a: {
level: 1,
b: {
level: 5,
c: {
level: 1,
message: "Hello"
}
},
d: "World."
}
}
Consider the following aggregation operation:
.. code-block:: javascript
db.test.aggregate(
{ $match: {} },
{ $redact: { $cond: { if: { $lt: [ '$level', 3 ] },
then: "$$DESCEND",
else: "$$PRUNE" }
}
}
)
This operation evaluates every object-typed field at every level for all
documents in the ``test`` collection, and uses the
:expression:`$cond` expression and the variables ``$$DESCEND``
and ``$$PRUNE`` to specify the redaction of document parts in the
aggregation pipeline.
Specifically, if the field ``level`` is less than 3, (i.e. ``{
$lt: [ '$level', 3' ] }``) :pipeline:`$redact` continues (i.e.
``$$DESCEND``) evaluating the fields and sub-documents at this
level of the input document. If the value of ``level`` is greater
than ``3``, then :pipeline:`$redact` removes all data at this
level of the document.
The result of this aggregation operation is as follows:
.. code-block:: javascript
{ a: {
level: 1,
d: "World."
} }
You may also specify ``$$KEEP`` as a variable to
:expression:`$cond`, which returns the entire sub-document
without traversing, as ``$$DESCEND``.
.. see:: :expression:`$cond`.
Set Expression Operations in ``$project``
`````````````````````````````````````````
In 2.5.2, the :pipeline:`$project` aggregation pipeline stage now
supports the following set expressions:
.. important:: Set operators take arrays as their arguments and treat
these arrays as sets. The set operators ignore duplicate entries in
an input array and produce arrays containing unique entries.
.. expression:: $setIsSubset
Takes two arrays and returns ``true`` when the first array is a
subset of the second and ``false`` otherwise.
.. expression:: $setEquals
Takes two arrays and returns ``true`` when they contain the same
elements, and ``false`` otherwise.
.. expression:: $setDifference
Takes two arrays and returns an array containing the elements that
only exist in the first array.
.. expression:: $setIntersection
Takes any number of arrays and returns an array that contains the
elements that appear in every input array.
.. expression:: $setUnion
Takes any number of arrays and returns an array that containing the
elements that appear in any input array.
.. expression:: $allElementsTrue
Takes a single expression that returns an array and returns ``true``
if all its values are ``true`` and ``false`` otherwise. An empty
array returns ``true``.
:expression:`$anyElementsTrue` was ``$all`` in versions of 2.5
before 2.5.3.
.. expression:: $anyElementTrue
Takes a single expression that returns an array and returns ``true``
if any of its values are ``true`` and ``false`` otherwise. An empty
array returns ``false``.
:expression:`$anyElementTrue` was ``$any`` in versions of 2.5 before
2.5.3.
``$map`` and ``$let`` Expressions in Aggregation Pipeline Stages
````````````````````````````````````````````````````````````````
.. tip:: For :expression:`$let` and :expression:`$map`, the
aggregation framework introduces variables. To specify a variable,
use the name of the variable prefixed by **2** dollar signs
(i.e. ``$$``) as in: ``$$<name>``.
The :expression:`$let` and :expression:`$map` make it possible to
declare and manipulate variables within an aggregation pipeline
stages, specifically the :pipeline:`$project`, :pipeline:`$group`, and
:pipeline:`$redact` stages. See: :doc:`/reference/operator/aggregation/let` and
:doc:`/reference/operator/aggregation/map` for more information.
.. expression:: $let
:expression:`$let` binds variables for use in sub-expressions. For
example:
.. code-block:: javascript
{ $project: { remaining: { $let: {
vars: { tally: 75, count: 50 },
in: { $subtract: [ "$$tally", "$$count" ] }
}
}
}
}
Would return a document with the following:
.. code-block:: javascript
{ remaining: 25 }
:expression:`$let` is available in the :pipeline:`$project`,
:pipeline:`$group`, and :pipeline:`$redact` pipeline stages.
.. expression:: $map
:expression:`$map` applies a sub-expression to each item in an
array and returns an array with the result of the sub-expression
:expression:`$map` is available in the :pipeline:`$project`,
:pipeline:`$group`, and :pipeline:`$redact` pipeline stages.
Given an input document that resembles the following:
.. code-block:: javascript
{ skews: [ 1, 1, 2, 3, 5, 8 ] }
And the following :pipeline:`$project` statement:
.. code-block:: javascript
{ $project: { adjustments: { $map: { input: "$skews",
as: "adj",
in: { $add: [ "$$adj", 100 ] } } } } }
The :expression:`$map` would transform the input document into the
following output document:
.. code-block:: javascript
{ adjustments: [ 101, 101, 102, 103, 105, 108 ] }
``$literal`` Expression for Aggregation Pipeline Stages
```````````````````````````````````````````````````````
The new :expression:`$literal` operator allows users to explicitly
specify documents in aggregation operations that the pipeline stage
would otherwise interpret directly. See
:doc:`/reference/operator/aggregation/literal` for more information.
``explain`` Option for the Aggregation Pipeline
```````````````````````````````````````````````
The new ``explain`` option for aggregation provides information about
how the command processes the pipeline. The returned document contains
information on each stage of the pipeline.
The intended readers of the ``explain`` output document are humans, and
not machines, and the output format is subject to change between
releases.
To use ``explain``, specify ``explain: true`` as the :ref:`second
parameter <aggregation-method-change>` to the
:method:`db.collection.aggregate()` helper:
.. include:: /includes/important-uses-new-aggregate-helper.rst
.. code-block:: javascript
db.collection.aggregate( [ <pipeline operations> ],
{explain: true }
)
.. example::
In the :program:`mongo` shell, given the following aggregation
.. code-block:: javascript
db.records.aggregate(
[ { $sort: { name : -1 } },
{ $limit: 5 }
],
{ explain: true }
)
The returned document provides information on how
:dbcommand:`aggregate` processed the pipeline. For this example, the
returned document may show, among other details, which index, if
any, the operation used. If the operation did not use an index and
since the :pipeline:`$sort` immediately precedes the
:pipeline:`$limit`, the output would show the :pipeline:`$sort`
operation only maintaining the top 5 results as it progresses rather
than sorting all input documents. If the ``record`` collection is a
sharded collection, the output also shows the division of labor
between the shards and the merge,, and for targeted queries, shows
the targeted shards.
For the :dbcommand:`aggregate` command, add the ``explain: true`` to the
command, as shown:
.. code-block:: javascript
db.runCommand( { aggregate: "<collection>",
explain: true,
pipeline: [ <pipeline operations> ] } )
``$cond`` Accepts Objects as Arguments
``````````````````````````````````````
.. versionadded:: 2.5.3
The ternary :expression:`$cond` expression can now take either an object
or an array. Previously :expression:`$cond` always took an array. See
:doc:`/reference/operator/aggregation/cond` for more information.
New ``$size`` Operator for the Aggregation Pipeline
```````````````````````````````````````````````````
.. include:: /includes/important-uses-new-aggregate-helper.rst
.. versionadded:: 2.5.3
The new :expression:`$size` operator for the :doc:`aggregation
pipeline </core/aggregation-pipeline>` returns the size of a specified
array. See :doc:`/reference/operator/aggregation/size` for more
information.
Write Operation Improvements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded 2.5.3
MongoDB has updated the wire protocol to include new ``insert``,
``update``, and ``delete`` commands for batch operations. You may
specify a single write concern for each batch of writes. The new
commands support a number of other configuration options including
the ability to proceed if any individual write fails.
MongoDB also introduces new changes to the update language:
``$mul`` Update Operator
````````````````````````
The new :update:`$mul` operator allows you to multiply the value of a
field by the specified amount. See :update:`$mul` for details.
``xor`` operation for ``$bit`` Operator
```````````````````````````````````````
The :update:`$bit` operator now supports bitwise updates using a logical
``xor`` operation. See the documentation of :update:`$bit` for more
information on bitwise updates. Consider the following operation:
``$min`` Update Operator
````````````````````````
The new :update:`$min` operator updates the value of the field to a
specified value *if* the specified value is **less than** the current
value of the field. See :update:`$min` for details.
``$max`` Update Operator
````````````````````````
The new :update:`$max` operator updates the value of the field to a
specified value *if* the specified value is **greater than** the
current value of the field. See :update:`$max` for details.
``$currentDate`` Update Operator
````````````````````````````````
The :update:`$currentDate` operator sets the value of a field to the
current date, either as a :ref:`Date <document-bson-type-date>` or a
:ref:`timestamp <document-bson-type-timestamp>`. See
:update:`$currentDate` for details.
Enhanced Modifiers for ``$push`` Update Operator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionchanged:: 2.5.3
The :update:`$push` operator has enhanced support for the
:update:`$sort`, :update:`$slice`, and :update:`$each` modifiers
to increase functionality and usability. MongoDB also provides a new
:update:`$position` modifier for the :update:`$push` operator.
``$each`` Modifier Changes
``````````````````````````
When used in conjunction with the :update:`$sort`, the
:update:`$slice`, and the :update:`$position` modifiers, the
:update:`$each` modifier no longer needs to be the first modifier for
the :update:`$push`.
``$sort`` Modifier Enhancements
```````````````````````````````
The :update:`$sort` modifier can sort the array elements as a whole.
This change means that the :update:`$sort` modifier can now sort
array elements that are not documents. Or, if the array elements are
documents, the modifier can sort by the whole documents, and not just
by the field in the documents. The :update:`$sort` no longer requires
the :update:`$slice` modifier. See :update:`$sort` for details.
``$slice`` Modifier Enhancements
````````````````````````````````
The :update:`$slice` modifier can accept positive numbers to slice
from the front of the array. See :update:`$slice` for details.
``$position`` Modifier
``````````````````````
The :update:`$position` modifier specifies the insert position for
the :update:`$push` operator. See :update:`$position`.
Sharding Improvements
~~~~~~~~~~~~~~~~~~~~~
Support for Removing Orphan Data From Shards
````````````````````````````````````````````
.. versionadded:: 2.5.2
The new :dbcommand:`cleanupOrphaned` is available to remove orphaned
data from a sharded cluster. Orphaned data are those documents in a
collection that exist on shards that belong to another shard in the
cluster. Orphaned data are the result of failed migrations or incomplete
migration cleanup due to abnormal shutdown.
.. dbcommand:: cleanupOrphaned
:dbcommand:`cleanupOrphaned` removes documents from *one* orphaned
chunk range on shard and runs directly on the shard's
:program:`mongod` instance, and requires the
:authrole:`clusterAdmin` for systems running with :setting:`auth`.
You do **not** need to disable the :term:`balancer` to run
:dbcommand:`cleanupOrphaned`.
In the common case, :dbcommand:`cleanupOrphaned` takes the
following form:
.. code-block:: javascript
{ cleanupOrphaned: <namespace>, startingFromKey: { } }
The ``startingFromKey`` field specifies the lowest value of the
:term:`shard key` to begin searching for orphaned data. The empty
document (i.e. ``{ }``) is equivalent to the minimum value for the
shard key (i.e. ``$minValue``).
The :dbcommand:`cleanupOrphaned` command returns a document that
contains a field named ``stoppedAtKey`` that you can use to
construct a loop, as in the following example in the
:program:`mongo` shell:
.. code-block:: javascript
db = db.getSiblingDB("admin")
var nextKey = {};
while (
nextKey = db.runCommand( { cleanupOrphaned : "test.user", startingFromKey : nextKey } ).stoppedAtKey
) { printjson(nextKey); }
This loop removes all orphaned data on the shard.
Ability to Merge Co-located Contiguous Chunks
`````````````````````````````````````````````
.. versionadded:: 2.5.2
The :dbcommand:`mergeChunks` provides the ability for users to combine
contiguous chunks located on a single shard. This makes it possible to
combine chunks in situations where document removal leaves a sharded
collection with too many empty chunks.
.. dbcommand:: mergeChunks
Combines two contiguous chunks located on the same shard. The
:dbcommand:`mergeChunks` takes the following form:
.. code-block:: javascript
{ mergeChunks: <namespace>, bounds: [ <minKey>, <maxKey> ] }
The ``bounds`` option specified to :dbcommand:`mergeChunks` *must*
be the boundaries of existing chunks in the collections. See the
output of :method:`sh.status()` to see the current shard
boundaries.
.. important:: Both chunks **must** reside on the same shard.
.. tip:: In 2.5.2, :dbcommand:`mergeChunks` has the following
restrictions, which are subject to change in future releases:
- :dbcommand:`mergeChunks` will only merge two chunks.
- one chunk **must** not hold any documents (i.e. an "empty
chunk").
.. _collection-level-access-control:
Collection-Level Access Control
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MongoDB 2.5.3 provides the ability to specify user privileges at a
collection-level granularity. To specify collection-level access
control, create a custom role that pairs its actions to a particular
collection in a specific database in the :ref:`resource document
<resource-document>`. The MongoDB :doc:`built-in roles
</reference/user-privileges>` grant privileges at a database-level
only, and thus cannot be used to control privileges at the
collection-level.
See :ref:`user-defined-roles` for more information.
.. _user-defined-roles:
User Defined Roles
~~~~~~~~~~~~~~~~~~
.. important:: For authentication/authorization, the 2.5.3 release does not
offer an automatic upgrade process to go from version 2.4 model for
user credentials and privileges to the 2.5.3 model. See
:ref:`authentication-incompatibility`.
In version 2.5.3, MongoDB 2.5.3 provides the ability to create custom
:ref:`user roles <custom-user-roles>` in addition to the roles provided by
MongoDB. In addition, MongoDB now provides global user management,
storing all user and user-defined role data in the ``admin`` database
and providing a new set of commands for managing users and roles.
MongoDB uses a role-based approach to authorization. A role grants
privileges to act on various :ref:`resources <resource-document>` to
the user with that role. To create a role is to define its privileges
by pairing resources (e.g. database, collection) with actions (e.g.
``insert``, ``find``), and/or by specifying other roles from which
the role inherits privileges. MongoDB stores the user-defined roles
information in the :ref:`system.roles <admin-system-roles-collection>`
collection of the ``admin`` database.
Both the user-defined roles and roles provided by MongoDB are available
for assignments to users. Assigning roles to a user authorizes the user
to have only the privileges granted by the roles.
User data includes the user's authentication credentials as well as any
roles assigned to the user. MongoDB stores the user data in the
:ref:`system.users <admin-system-users-collection>` collection of the
``admin`` database.
.. _resource-document:
Resource Document
`````````````````
The resource document specifies the resources upon which the
``actions`` for that privilege(s) are permitted.
The resource document can specify a database and a collection:
.. code-block:: javascript
{ db: <database>, collection: <collection> }
If both the ``db`` field and the ``collection`` field are specified,
the resource is the specified collection in the specified database,
providing :ref:`collection-level access control
<collection-level-access-control>`.
If the ``db`` field is an empty string ``""``, the resource is all
collections with the specified name across databases.
If the ``collection`` field is an empty string ``""``, then the
resource is the whole database, excluding the system collections.
If both the ``db`` field and the ``collection`` field are empty strings
``""``, then the resource is all collections, excluding the system
collections, in all the databases.
.. _exclude-system-collections:
.. note:: When you grant access to a full database, the system
collections are excluded, unless you name them explicitly. System
collections include but are not limited to the following:
- :data:`<database>.system.profile`
- :data:`<database>.system.namespaces`
- :data:`<database>.system.indexes`
- :data:`<database>.system.js`
- :data:`local.system.replset`
- :ref:`admin.system.users <admin-system-users-collection>`
- :ref:`admin.system.roles <admin-system-roles-collection>`
Or, the resource document can specify the cluster, as in:
.. code-block:: javascript
{ cluster : true }
Use the ``cluster`` resource for actions that affect the state of the
system rather than act on specific set of databases and/or collections.
Examples of such actions are ``shutdown``, ``replSetReconfig``, and
``enableSharding``. For example, the following privilege document
grants the action ``shutdown`` on the ``cluster``.
.. code-block:: javascript
{ resource: { cluster : true }, actions: [ "shutdown" ] }
New Schema for User and Role Data
`````````````````````````````````
MongoDB stores all user and role information for a system in a single
database, the ``admin`` database, and no longer stores information
separately in each database. The :doc:`system.users
</reference/privilege-documents>` collections in non-``admin``
databases are deprecated, and you can no longer manage users and roles
through updates to these collections. In the ``admin`` database,
MongoDB stores the user-defined roles information in the
:ref:`system.roles <admin-system-roles-collection>` collection and the
users information in the :ref:`system.users
<admin-system-users-collection>` collection.
To manage users and roles, use the new :ref:`user management commands
<user-management-commands>` and :ref:`role-management commands
<role-management-commands>`.
.. todo: Add this to the RNs when the command is ready:
For upgrades, MongoDB provides the ``upgradeUsers`` command to
migrate data from the deprecated collections.
.. todo: When we write the upgrade document, use this info from Andy
as appropriate:
Upgrade all of the nodes to 2.6 (including the config servers), and
then run the upgradeUsers command. When that command returns ok: 1,
the upgrade is complete. If that command fails to return or returns
some other value, it is always safe to run again.
To upgrade a single node, run upgradeUsers on that node. For a
replicaset, run it on the primary. For a sharded cluster, run it on
*one* mongos, and then run it on the primary of each shard. In this
last case, the upgrades are independent. If one fails, you only have
to rerun that one, not all of them.
.. _admin-system-roles-collection:
``system.roles`` Schema
^^^^^^^^^^^^^^^^^^^^^^^
MongoDB stores the user-defined roles information globally in the
``system.roles`` collection of the ``admin`` database and provides
access through the :ref:`role-management commands
<role-management-commands>`.