Skip to content

Commit f8699f8

Browse files
committed
DOCSP-49279:
1 parent 611a739 commit f8699f8

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

source/fundamentals/linq.txt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ You can print the results of the preceding example as follows:
135135

136136
var results = query.ToCursor();
137137

138-
139138
Supported Aggregation Stages
140139
----------------------------
141140

@@ -519,7 +518,7 @@ The ``$group`` aggregation stage separates documents into groups according to
519518
the criteria you specify.
520519

521520
Select the :guilabel:`Method Syntax` or :guilabel:`Query Syntax` tab to see how
522-
to generate an ``$group`` stage using LINQ:
521+
to generate a ``$group`` stage using LINQ:
523522

524523
.. tabs::
525524

@@ -570,7 +569,7 @@ The ``$sort`` aggregation stage returns the results of your query in the order
570569
that you specify.
571570

572571
Select the :guilabel:`Method Syntax` or :guilabel:`Query Syntax` tab to see how
573-
to generate an ``$sort`` stage using LINQ:
572+
to generate a ``$sort`` stage using LINQ:
574573

575574
.. tabs::
576575

@@ -609,6 +608,35 @@ The following is a subset of the documents contained in the returned results:
609608
{ "_id" : ObjectId(...), "name" : "Abaleh", "restaurant_id" : "50009096", "cuisine" : "Mediterranean", "address" : { ... }, "borough" : "Manhattan", "grades" : [...] }
610609
...
611610

611+
.. _csharp-linq-convert:
612+
613+
$convert
614+
~~~~~~~~
615+
616+
You can use the ``Mql.Convert()`` method in a ``Select()`` projection to
617+
convert a value from one type to a different specified type. You can
618+
use To learn more about conversion behavior and permitted conversions,
619+
see the :manual:`$convert reference
620+
</reference/operator/aggregation/convert/>` in the {+mdb-server+} manual.
621+
622+
The ``Convert()`` method takes the following parameters:
623+
624+
- Value to convert.
625+
- ``ConvertOptions<Tto>`` instance that specifies the type to convert to
626+
and options. Some conversions require certain options to be set, but
627+
you can also set options to handle errors or null values.
628+
629+
The following code converts the ``RestaurantId`` string values to
630+
``int`` values in a projection by using LINQ:
631+
632+
.. code-block:: csharp
633+
634+
var query = queryableCollection
635+
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>()));
636+
637+
The converted values in the output documents are stored under the original
638+
field name.
639+
612640
$lookup
613641
~~~~~~~
614642

@@ -967,7 +995,6 @@ The result contains the following values:
967995
0
968996
1
969997

970-
971998
Unsupported Aggregation Stages
972999
------------------------------
9731000

@@ -1005,6 +1032,9 @@ The following are some methods supported by the {+driver-long+} implementation o
10051032
* - ``LongCount``
10061033
- Returns an ``Int64`` that represents the number of documents that match the specified criteria
10071034

1035+
* - ``Convert`` (only in ``Select`` projections)
1036+
- Converts a value from one type to a different specified type
1037+
10081038
* - ``DateFromString``
10091039
- Converts a ``string`` to a ``DateTime`` object
10101040

source/whats-new.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ What's New
2020

2121
Learn what's new in:
2222

23+
* :ref:`Version 3.4 <csharp-version-3.4>`
2324
* :ref:`Version 3.3 <csharp-version-3.3>`
2425
* :ref:`Version 3.2 <csharp-version-3.2>`
2526
* :ref:`Version 3.1 <csharp-version-3.1>`
@@ -41,6 +42,17 @@ In accordance with the `MongoDB Software Lifecycle Schedules
4142
version of {+driver-short+} will raise the minimum {+mdb-server+} version from
4243
4.0 to 4.2. {+driver-short+} will no longer support {+mdb-server+} 4.0.
4344

45+
.. _csharp-version-3.4:
46+
47+
What's New in 3.4
48+
-----------------
49+
50+
The 3.4 driver release includes the following new features:
51+
52+
- Adds the ``Mql.Convert()`` LINQ method to convert between types when
53+
performing aggregations. To learn more, see the
54+
:ref:`csharp-linq-convert` section of the LINQ guide.
55+
4456
.. _csharp-version-3.3:
4557

4658
What's New in 3.3

0 commit comments

Comments
 (0)