@@ -135,17 +135,17 @@ You can print the results of the preceding example as follows:
135
135
136
136
var results = query.ToCursor();
137
137
138
-
139
138
Supported Aggregation Stages
140
139
----------------------------
141
140
142
- You can use LINQ to create an :ref :`aggregation pipeline <aggregation-pipeline-intro >`.
141
+ You can use LINQ to create an :manual :`aggregation pipeline </core/ aggregation-pipeline/ >`.
143
142
The {+driver-short+} automatically translates each LINQ statement into the corresponding
144
143
aggregation pipeline stages. In this section you can learn which
145
144
aggregation pipeline stages are supported.
146
145
147
- To learn more about the aggregation pipeline stages, see the
148
- :ref:`aggregation-pipeline-operator-reference` page in the server manual.
146
+ To learn more about the aggregation pipeline stages, see
147
+ :manual:`Aggregation Stages </reference/operator/aggregation-pipeline/>`
148
+ in the {+mdb-server+} manual.
149
149
150
150
$project
151
151
~~~~~~~~
@@ -519,7 +519,7 @@ The ``$group`` aggregation stage separates documents into groups according to
519
519
the criteria you specify.
520
520
521
521
Select the :guilabel:`Method Syntax` or :guilabel:`Query Syntax` tab to see how
522
- to generate an ``$group`` stage using LINQ:
522
+ to generate a ``$group`` stage using LINQ:
523
523
524
524
.. tabs::
525
525
@@ -570,7 +570,7 @@ The ``$sort`` aggregation stage returns the results of your query in the order
570
570
that you specify.
571
571
572
572
Select the :guilabel:`Method Syntax` or :guilabel:`Query Syntax` tab to see how
573
- to generate an ``$sort`` stage using LINQ:
573
+ to generate a ``$sort`` stage using LINQ:
574
574
575
575
.. tabs::
576
576
@@ -793,6 +793,16 @@ in the Atlas manual. For more examples about running Atlas Vector Search queries
793
793
{+driver-short+}, see :atlas:`Run Vector Search Queries </atlas-vector-search/vector-search-stage/>`
794
794
in the Atlas manual and select :guilabel:`C#` from the language dropdown.
795
795
796
+ Aggregation Operators
797
+ ---------------------
798
+
799
+ You can use :manual:`aggregation pipeline operators
800
+ </reference/operator/aggregation/>` in your aggregation stages to modify
801
+ documents and perform calculations.
802
+
803
+ The following sections describe aggregation operators that you can
804
+ implement by using LINQ methods.
805
+
796
806
Bitwise Operators
797
807
~~~~~~~~~~~~~~~~~
798
808
@@ -967,6 +977,42 @@ The result contains the following values:
967
977
0
968
978
1
969
979
980
+ .. _csharp-linq-convert:
981
+
982
+ $convert
983
+ ~~~~~~~~
984
+
985
+ The ``$convert`` operator converts a value to a specified type. You can
986
+ use this operator to perform type conversions in stages such as
987
+ ``$project``, ``$addFields``, and ``$set``.
988
+
989
+ In the driver, you can use the ``Mql.Convert()`` method to
990
+ convert a value from one type to a different specified type. To learn
991
+ more about conversion behavior and permitted conversions, see the
992
+ :manual:`$convert reference </reference/operator/aggregation/convert/>`
993
+ in the {+mdb-server+} manual.
994
+
995
+ The ``Convert()`` method takes the following parameters:
996
+
997
+ - Value to convert.
998
+ - ``ConvertOptions`` instance that specifies the type to convert to
999
+ and options. Some conversions require you to specify certain options, but
1000
+ you can also set options to handle errors or null values.
1001
+
1002
+ The following code performs the following actions by using LINQ methods:
1003
+
1004
+ - Converts the ``RestaurantId`` string values to ``int`` values in a
1005
+ ``Select()`` projection
1006
+ - Sets the returned value to ``-1`` if an error occurs during conversion
1007
+ - Sets the returned value to ``0`` if the input value is ``null`` or missing
1008
+
1009
+ .. code-block:: csharp
1010
+
1011
+ var query = queryableCollection
1012
+ .Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int> { OnError = -1, OnNull = 0 }));
1013
+
1014
+ The driver stores the converted values under the original field name in
1015
+ the output documents.
970
1016
971
1017
Unsupported Aggregation Stages
972
1018
------------------------------
@@ -984,7 +1030,8 @@ the :ref:`<csharp-builders-out>` section.
984
1030
Supported Methods
985
1031
-----------------
986
1032
987
- The following are some methods supported by the {+driver-long+} implementation of LINQ:
1033
+ The following table describes some methods supported by the
1034
+ {+driver-long+} implementation of LINQ:
988
1035
989
1036
.. list-table::
990
1037
:header-rows: 1
@@ -1005,6 +1052,9 @@ The following are some methods supported by the {+driver-long+} implementation o
1005
1052
* - ``LongCount``
1006
1053
- Returns an ``Int64`` that represents the number of documents that match the specified criteria
1007
1054
1055
+ * - ``Convert``
1056
+ - Converts a value from one type to a different specified type
1057
+
1008
1058
* - ``DateFromString``
1009
1059
- Converts a ``string`` to a ``DateTime`` object
1010
1060
0 commit comments