You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Docs/reference/content/reference/driver/crud/reading.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ var result = await collection.Find(filter)
106
106
107
107
## Aggregation
108
108
109
-
MongoDB offers the [aggregation framework]({{< docsref "core/aggregation-pipeline/" >}}) which can be accessed via the [`Aggregate`]({{< apiref "M_MongoDB_Driver_IMongoCollectionExtensions_Aggregate__1" >}}) method. The result type is [`IAggregateFluent`]({{< apiref "T_MongoDB_Driver_IAggregateFluent_1" >}}) and provides access to build up and aggregation pipeline.
109
+
MongoDB offers the [aggregation framework]({{< docsref "core/aggregation-pipeline/" >}}) which can be accessed via the [`Aggregate`]({{< apiref "M_MongoDB_Driver_IMongoCollectionExtensions_Aggregate__1" >}}) method. The result type is [`IAggregateFluent`]({{< apiref "T_MongoDB_Driver_IAggregateFluent_1" >}}) and provides access to a fluent API to build up an aggregation pipeline.
110
110
111
111
The first example from [MongoDB's documentation]({{< docsref "tutorial/aggregation-zip-code-data-set/#return-states-with-populations-above-10-million" >}}) is done in a type-safe manner below:
This will result in the following aggregation pipeline getting sent to the server:
@@ -147,11 +148,11 @@ More samples are located in the [source]({{< srcref "MongoDB.Driver.Tests/Sample
147
148
148
149
All the [stage operators]({{< docsref "reference/operator/aggregation/#aggregation-pipeline-operator-reference" >}}) are supported, however some of them must use the [`AppendStage`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_AppendStage__1" >}}) method due to lack of support for certain projections in the language.
149
150
150
-
{{% note class="important" %}}Unlike `Find`, the order that stages are defined in matters. `Skip(10).Limit(10)` is not the same as `Limit(10).Skip(10)`.{{% /note %}}
151
+
{{% note class="important" %}}Unlike `Find`, the order that stages are defined in matters. `Skip(10).Limit(20)` is not the same as `Limit(20).Skip(10)`.{{% /note %}}
151
152
152
153
#### $project
153
154
154
-
A `$project` is rendered using the [`Project`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Project__1" >}}) method and its overloads. Unlike in `Find`, an aggregate projection is not executed client-side and must be fully translatable to the server's supported expressions. See [expressions]({{< relref "reference\driver\expressions.md#projections" >}}) for more detail about the expressions available inside a $project.
155
+
A `$project` is defined using the [`Project`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Project__1" >}}) method and its overloads. Unlike in `Find`, an aggregate projection is not executed client-side and must be fully translatable to the server's supported expressions. See [expressions]({{< relref "reference\driver\expressions.md#projections" >}}) for more detail about the expressions available inside a $project.
@@ -164,7 +165,7 @@ Project(x => new { Name = x.FirstName + " " + x.LastName });
164
165
165
166
#### $match
166
167
167
-
A `$match` stage is rendered using the [`Match`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Match" >}}) method and its overloads. It follows the same requirements as that of `Find`.
168
+
A `$match` stage is defined using the [`Match`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Match" >}}) method and its overloads. It follows the same requirements as that of `Find`.
168
169
169
170
```csharp
170
171
Match(x=>x.Age>21);
@@ -179,7 +180,7 @@ There is no method defined for a `$redact` stage. However, it can be added using
179
180
180
181
#### $limit
181
182
182
-
A `$limit` stage is rendered using the [`Limit`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Limit" >}}) method.
183
+
A `$limit` stage is defined using the [`Limit`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Limit" >}}) method.
183
184
184
185
```csharp
185
186
Limit(20);
@@ -190,7 +191,7 @@ Limit(20);
190
191
191
192
#### $skip
192
193
193
-
A `$skip` stage is rendered using the [`Skip`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Skip" >}}) method.
194
+
A `$skip` stage is defined using the [`Skip`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Skip" >}}) method.
194
195
195
196
```csharp
196
197
Skip(20);
@@ -201,7 +202,7 @@ Skip(20);
201
202
202
203
#### $unwind
203
204
204
-
An `$unwind` stage is rendered using the [`Unwind`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Unwind__1" >}}) method and its overloads. Because $unwind is a type of projection, you must provide a return type, although not specifying one will use the overload that projects into a [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}).
205
+
An `$unwind` stage is defined using the [`Unwind`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Unwind__1" >}}) method and its overloads. Because $unwind is a type of projection, you must provide a return type, although not specifying one will use the overload that projects into a [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}).
A `$group` stage is rendered using the [`Group`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Group__1" >}}) method and its overloads. Because $unwind is a type of projection, you must provide a return type. The most useful of the overloads is where 2 lambda expressions are expressed, the first for the key and the second for the grouping. See [expressions]({{< relref "reference\driver\expressions.md#grouping" >}}) for more detail about the expressions available inside a $group.
216
+
A `$group` stage is defined using the [`Group`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Group__1" >}}) method and its overloads. Because $unwind is a type of projection, you must provide a return type. The most useful of the overloads is where two lambda expressions are expressed, the first for the key and the second for the grouping. See [expressions]({{< relref "reference\driver\expressions.md#grouping" >}}) for more detail about the expressions available inside a $group.
@@ -225,7 +226,7 @@ As in project, it is required that the result of the grouping be a new type, eit
225
226
226
227
#### $sort
227
228
228
-
A `$sort` stage is rendered using the [`Sort`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Sort" >}}) method. However, `SortBy`, `SortByDescending`, `ThenBy`, and `ThenByDescending` are also present.
229
+
A `$sort` stage is defined using the [`Sort`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Sort" >}}) method. However, `SortBy`, `SortByDescending`, `ThenBy`, and `ThenByDescending` are also available.
229
230
230
231
```csharp
231
232
SortBy(x=>x.LastName).ThenByDescending(x=>x.Age);
@@ -240,10 +241,10 @@ There is no method defined for a `$geoNear` stage. However, it can be added usin
240
241
241
242
#### $out
242
243
243
-
A `$out` stage is rendered using the [`Out`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_Out" >}}) method.
244
+
A `$out` stage is defined using the [`OutAsync`]({{< apiref "M_MongoDB_Driver_IAggregateFluent_1_OutAsync" >}}) method. It must be the final stage and it triggers execution of the operation.
We'll walk through the supported expressions below. The [tests]({{< srcref "MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Project.cs" >}}) are also a good reference.
308
308
@@ -799,11 +799,11 @@ p => p.Name ?? "awesome";
799
799
800
800
See the [MongoDB documentation]({{< docsref "meta/aggregation-quick-reference/#accumulators" >}}) for more information on each operator.
801
801
802
-
Also, the [tests]({{< srcref "MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Group.cs" >}}) are also a good reference.
802
+
Also, the [tests]({{< srcref "MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Group.cs" >}}) are a good reference.
803
803
804
804
{{% note %}}These are only supported in a grouping expression.{{% /note %}}
805
805
806
-
In the below, it should be assumed that `g` is of type [`IGrouping<TKey, TElement>`]({{< msdnref "bb344977" >}}).
806
+
In the examples below, it should be assumed that `g` is of type [`IGrouping<TKey, TElement>`]({{< msdnref "bb344977" >}}).
0 commit comments