1
- .. _kotlin-sync-sync- aggregation-expression-operations:
1
+ .. _kotlin-sync-aggregation-expression-operations:
2
2
3
3
=================================
4
4
Aggregation Expression Operations
@@ -72,13 +72,13 @@ value of ``1.0``:
72
72
of(1.0)
73
73
74
74
To create an operation, chain a method to your field or value reference.
75
- You can build more complex operations by chaining other methods.
75
+ You can build more complex operations by chaining multiple methods.
76
76
77
77
The following example creates an operation to find patients in New
78
78
Mexico who have visited the doctor’s office at least once. The operation
79
79
performs the following actions:
80
80
81
- - Checks if the size of the ``visitDates`` array is greater than ``0``
81
+ - Checks if the size of the ``visitDates`` array value is greater than ``0``
82
82
by using the ``gt()`` method
83
83
- Checks if the ``state`` field value is “New Mexico” by using the
84
84
``eq()`` method
@@ -112,11 +112,7 @@ how to include your expression in common aggregates builder methods:
112
112
- ``group(<expression>)``
113
113
114
114
.. TODO To learn more about these methods, see the
115
- .. :ref:`kotlin-sync-sync-aggregation`.
116
-
117
- The examples use the ``listOf()`` method to create a list of
118
- aggregation stages. Then, the examples pass the pipeline to the
119
- ``aggregate()`` method of ``MongoCollection``.
115
+ .. :ref:`kotlin-sync-aggregation`.
120
116
121
117
Constructor Methods
122
118
-------------------
@@ -195,6 +191,10 @@ the Server manual documentation. While each method is effectively
195
191
equivalent to the corresponding Query API expression, they may differ in
196
192
expected parameters and implementation.
197
193
194
+ The example in each section uses the ``listOf()`` method to create a
195
+ pipeline from the aggregation stage. Then, each example passes the
196
+ pipeline to the ``aggregate()`` method of ``MongoCollection``.
197
+
198
198
.. note::
199
199
200
200
The driver generates a Query API expression that may be different
@@ -250,8 +250,8 @@ You can perform an arithmetic operation on a value of type ``MqlInteger`` or
250
250
- :manual:`$subtract </reference/operator/aggregation/subtract/>`
251
251
252
252
Suppose you have weather data for a specific year that includes the
253
- precipitation measurement (in inches) for each day. You want find the average
254
- precipitation, in millimeters, for each month.
253
+ precipitation measurement (in inches) for each day. You want to find the
254
+ average precipitation, in millimeters, for each month.
255
255
256
256
The ``multiply()`` operator multiplies the ``precipitation`` field by
257
257
``25.4`` to convert the value to millimeters. The ``avg()`` accumulator method
@@ -389,18 +389,20 @@ following:
389
389
The ``filter()`` method displays only the results matching the provided
390
390
predicate. In this case, the predicate uses ``sum()`` to calculate the
391
391
total number of seats and compares that value to the number of ``ticketsBought``
392
- with ``lt()``. The ``project()`` method stores these filtered results as a new
393
- ``availableShowtimes`` array.
392
+ by using the ``lt()`` method . The ``project()`` method stores these
393
+ filtered results as a new ``availableShowtimes`` array field .
394
394
395
395
.. tip::
396
396
397
- You must specify the type of the array that you retrieve with the
398
- ``getArray()`` method if you work with the values of the
399
- array as their specific type.
397
+ You must specify the type of values that an array contains when using
398
+ the ``getArray()`` method to work with the values as any specific
399
+ type. For example, you must specify that an array contains integers
400
+ if you want to perform calculations with those integers elsewhere in
401
+ your application.
400
402
401
- In this example, we specify that the ``seats`` array contains values
402
- of type ``MqlDocument`` so that we can extract nested fields from
403
- each array entry.
403
+ The example in this section specifies that the ``seats`` array
404
+ contains values of type ``MqlDocument`` so that it can extract nested
405
+ fields from each array entry.
404
406
405
407
The following code shows the pipeline for this aggregation:
406
408
@@ -414,8 +416,8 @@ The following code shows the pipeline for this aggregation:
414
416
.. note::
415
417
416
418
To improve readability, the previous example assigns intermediary values to
417
- the ``totalSeats`` and ``isAvailable`` variables. If you don't pull
418
- out these intermediary values into variables, the code still produces
419
+ the ``totalSeats`` and ``isAvailable`` variables. If you don't assign
420
+ these intermediary values to variables, the code still produces
419
421
equivalent results.
420
422
421
423
The following code provides an equivalent aggregation pipeline in
@@ -459,8 +461,9 @@ Suppose you want to classify very low or high weather temperature
459
461
readings (in degrees Fahrenheit) as extreme.
460
462
461
463
The ``or()`` operator checks to see if temperatures are extreme by comparing
462
- the ``temperature`` field to predefined values with ``lt()`` and ``gt()``.
463
- The ``project()`` method records this result in the ``extremeTemp`` field.
464
+ the ``temperature`` field to predefined values by using the ``lt()`` and
465
+ ``gt()`` methods. The ``project()`` method records this result in the
466
+ ``extremeTemp`` field.
464
467
465
468
The following code shows the pipeline for this aggregation:
466
469
@@ -675,13 +678,12 @@ how the values compare:
675
678
676
679
.. tip::
677
680
678
- One advantage of using the ``passTo()`` method is that you can reuse
679
- your custom methods for other aggregations. You could
681
+ Using the ``passTo()`` method allows you to reuse
682
+ your custom methods for other aggregations. For example, you can
680
683
use the ``gradeAverage()`` method to find the average of grades for
681
684
groups of students filtered by entry year or district, not just their
682
- class, for example. You could use the ``evaluate()`` method to evaluate, for
683
- example, an individual student's performance, or an entire school's or
684
- district's performance.
685
+ class. Similarly, you could use the ``evaluate()`` method to evaluate
686
+ an individual student's performance or an entire school's performance.
685
687
686
688
The ``passArrayTo()`` method takes an array of all students and calculates the
687
689
average score by using the ``gradeAverage()`` method. Then, the
@@ -832,10 +834,10 @@ valid dates, such as ``"2018-01-15T16:00:00Z"`` or ``"Jan 15, 2018, 12:00
832
834
PM EST"``, you can use the ``parseDate()`` method to convert the strings
833
835
into date types.
834
836
835
- The ``dayOfWeek()`` method determines which day of the week it is and converts
836
- it to a number based on which day is a Monday according to the
837
- ``"America/New_York"`` parameter . The ``eq()`` method compares this value to
838
- ``2``, which corresponds to Monday based on the provided timezone parameter .
837
+ The ``dayOfWeek()`` method determines which day of the week that a date
838
+ is, then converts it to a number. The number assignment uses ``0`` to mean
839
+ Sunday when using the ``"America/New_York"`` timezone . The ``eq()``
840
+ method compares this value to ``2``, or Monday.
839
841
840
842
The following code shows the pipeline for this aggregation:
841
843
0 commit comments