@@ -169,9 +169,124 @@ on the ``name`` field.
169169 When sorting on fields with a boolean value, entities with a field value of
170170 ``false`` show before those with a value of ``true``.
171171
172+ Scalar Aggregations
173+ -------------------
174+
175+ The {+provider-short+} supports the following scalar aggregation methods:
176+
177+ - ``Count()``: Returns the number of elements in a collection or the number of
178+ documents that match a predicate
179+ - ``LongCount()``: Returns the number of elements in a collection as a ``long``
180+ or the number of documents that match a predicate
181+ - ``Any()``: Returns ``true`` if any elements in a collection match the predicate
182+ - ``Max()``: Returns the maximum value of a specified field in a collection
183+ - ``Min()``: Returns the minimum value of a specified field in a collection
184+ - ``Sum()``: Returns the sum of values of a specified field in a collection
185+ - ``Average()``: Returns the average of values of a specified field in a collection
186+
187+ The following sections show examples of each of the preceding methods.
188+
189+ Count
190+ ~~~~~
191+
192+ The following example uses the ``Count()`` method to count the number of elements in the
193+ ``Planets`` collection:
194+
195+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
196+ :language: csharp
197+ :start-after: // start-count
198+ :end-before: // end-count
199+
200+ The following example uses the ``Count()`` method to count the number of elements in the
201+ ``Planets`` collection that have a ``hasRings`` field set to ``true``:
202+
203+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
204+ :language: csharp
205+ :start-after: // start-count-predicate
206+ :end-before: // end-count-predicate
207+
208+ LongCount
209+ ~~~~~~~~~
210+
211+ The following example uses the ``LongCount()`` method to count the number of
212+ elements in the ``Planets`` collection and returns the result as a ``long``:
213+
214+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
215+ :language: csharp
216+ :start-after: // start-long-count
217+ :end-before: // end-long-count
218+
219+ The following example uses the ``LongCount()`` method to count the number of
220+ elements in the ``Planets`` collection that have a ``hasRings`` field set to
221+ ``true`` and returns the result as a ``long``:
222+
223+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
224+ :language: csharp
225+ :start-after: // start-long-count-predicate
226+ :end-before: // end-long-count-predicate
227+
228+ Any
229+ ~~~
230+
231+ The following example uses the ``Any()`` method to check if any elements in the
232+ ``Planets`` collection have a ``hasRings`` field set to ``true``:
233+
234+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
235+ :language: csharp
236+ :start-after: // start-any
237+ :end-before: // end-any
238+
239+ Max
240+ ~~~
241+
242+ The following example uses the ``Max()`` method to find the maximum value of the
243+ ``orderFromSun`` field in the ``Planets`` collection:
244+
245+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
246+ :language: csharp
247+ :start-after: // start-max
248+ :end-before: // end-max
249+
250+ Min
251+ ~~~
252+
253+ The following example uses the ``Min()`` method to find the minimum value of the
254+ ``orderFromSun`` field in the ``Planets`` collection:
255+
256+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
257+ :language: csharp
258+ :start-after: // start-min
259+ :end-before: // end-min
260+
261+ Sum
262+ ~~~
263+
264+ The following example uses the ``Sum()`` method to find the sum of the
265+ ``mass`` field in the ``Planets`` collection:
266+
267+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
268+ :language: csharp
269+ :start-after: // start-sum
270+ :end-before: // end-sum
271+
272+ Average
273+ ~~~~~~~
274+
275+ The following example uses the ``Average()`` method to find the average value of
276+ the ``mass`` field in the ``Planets`` collection:
277+
278+ .. literalinclude:: /includes/fundamentals/code-examples/aggregation.cs
279+ :language: csharp
280+ :start-after: // start-average
281+ :end-before: // end-average
282+
283+
172284Additional Information
173285----------------------
174286
287+ To learn more about aggregations in MongoDB, see the :manual:`Aggregation
288+ Operations </aggregation>` guide in the {+mdb-server+} manual.
289+
175290To learn more about the methods discussed in this guide, see the following .NET API
176291documentation links:
177292
0 commit comments