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/definitions.md
+44-44Lines changed: 44 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ title = "Definitions and Builders"
11
11
12
12
## Definitions and Builders
13
13
14
-
The driver has introduced a number of types related to the specification of filters, updates, projections, sorts, and index keys. These types are used throughout the [API]({{< relref "reference\driver\crud\index.md" >}}).
14
+
The driver has introduced a number of types related to the specification of filters, updates, projections, sorts, and index keys. These types are used throughout the [API]({{< relref "reference\driver\crud\index.md" >}}).
15
15
16
16
Most of the definitions also have builders to aid in their creation. Each builder has a generic type parameter `TDocument` which represents the type of document with which you are working. It will almost always match the generic `TDocument` parameter used in an [`IMongoCollection<TDocument>`]({{< apiref "T_MongoDB_Driver_IMongoCollection_1" >}}).
17
17
@@ -29,11 +29,11 @@ However, if you are working with a [mapped class]({{< relref "reference\bson\map
29
29
```csharp
30
30
classPerson
31
31
{
32
-
[BsonElement("fn")]
33
-
publicstringFirstName { get; set; }
32
+
[BsonElement("fn")]
33
+
publicstringFirstName { get; set; }
34
34
35
-
[BsonElement("ln")]
36
-
publicstringLastName { get; set; }
35
+
[BsonElement("ln")]
36
+
publicstringLastName { get; set; }
37
37
}
38
38
```
39
39
@@ -65,7 +65,7 @@ FilterDefinition<BsonDocument> filter = new BsonDocument("x", 1);
65
65
Both of these will render the filter `{ x: 1 }`.
66
66
67
67
68
-
### Filter Definition Builder
68
+
### Filter Definition Builder
69
69
70
70
_See the [tests]({{< testref "MongoDB.Driver.Tests/FilterDefinitionBuilderTests.cs" >}}) for examples._
For more information on valid lambda expressions, see the [expressions documentation]({{< relref "reference\driver\expressions.md" >}}).
116
116
117
-
#### Array Operators
117
+
#### Array Operators
118
118
119
119
When using entities with properties or fields that serialize to arrays, you can use the methods prefixed with "Any" to compare the entire array against a single item.
A pipeline definition defines an entire aggregation pipeline. It is implicitly convertible from a [`List<BsonDocument>`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}), a [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}), a [`List<IPipelineStageDefinition>`]({{< apiref "T_MongoDB_Driver_IPipelineStageDefinition" >}}) , and a [`IPipelineStageDefinition[]`]({{< apiref "T_MongoDB_Driver_IPipelineStageDefinition" >}}).
141
+
A pipeline definition defines an entire aggregation pipeline. It is implicitly convertible from a [`List<BsonDocument>`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}), a [`BsonDocument[]`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}), a [`List<IPipelineStageDefinition>`]({{< apiref "T_MongoDB_Driver_IPipelineStageDefinition" >}}) , and a [`IPipelineStageDefinition[]`]({{< apiref "T_MongoDB_Driver_IPipelineStageDefinition" >}}).
@@ -170,7 +170,7 @@ ProjectionDefinition<BsonDocument> projection = new BsonDocument("x", 1);
170
170
Both of these will render the projection `{ x: 1 }`.
171
171
172
172
173
-
### Projection Definition Builder
173
+
### Projection Definition Builder
174
174
175
175
_See the [tests]({{< testref "MongoDB.Driver.Tests/ProjectionDefinitionBuilderTests.cs" >}}) for examples._
176
176
@@ -185,13 +185,13 @@ Using the `Widget` class:
185
185
```csharp
186
186
classWidget
187
187
{
188
-
publicObjectIdId { get; set; }
188
+
publicObjectIdId { get; set; }
189
189
190
-
[BsonElement("x")]
191
-
publicintX { get; set; }
190
+
[BsonElement("x")]
191
+
publicintX { get; set; }
192
192
193
-
[BsonElement("y")]
194
-
publicintY { get; set; }
193
+
[BsonElement("y")]
194
+
publicintY { get; set; }
195
195
}
196
196
```
197
197
@@ -221,7 +221,7 @@ This last projection where we've used the [`Expression`]({{< apiref "M_MongoDB_D
221
221
The driver supports using expression trees to render projections. The same expression tree will sometimes render differently when used in a Find operation versus when used in an Aggregate operation. Inherently, a lambda expression contains all the information necessary to form both the projection on the server as well as the client-side result and requires no further information.
222
222
223
223
224
-
##### Find
224
+
##### Find
225
225
226
226
_See the [tests]({{< testref "MongoDB.Driver.Tests/Linq/Translators/FindProjectionTranslatorTests.cs" >}}) for examples._
The `_id` field is excluded automatically when we know for certain that it isn't necessary, as is the case in all the above examples.
258
258
259
259
260
-
##### Aggregate
260
+
##### Aggregate
261
261
262
262
_See the [tests]({{< testref "MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Project.cs" >}}) for examples._
263
263
264
264
When an aggregate projection is defined using a lambda expression, a majority of the [aggregation expression operators]({{< docsref "reference/operator/aggregation/#expression-operators" >}}) are supported and translated. Unlike a project for Find, no part of the lambda expression is run client-side. This means that all expressions in a projection for the [Aggregation Framework]({{< docsref "core/aggregation-pipeline/" >}}) must be expressible on the server.
265
265
266
266
267
-
##### Grouping
267
+
##### Grouping
268
268
269
269
_See the [tests]({{< testref "MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Group.cs" >}}) for examples._
270
270
271
-
A projection is also used when performing grouping in the [Aggregation Framework]({{< docsref "core/aggregation-pipeline/" >}}). In addition to the expression operators used in an aggregate projection, the [aggregation accumulator operators]({{< docsref "reference/operator/aggregation/group/#accumulator-operator" >}}) are also supported.
271
+
A projection is also used when performing grouping in the [Aggregation Framework]({{< docsref "core/aggregation-pipeline/" >}}). In addition to the expression operators used in an aggregate projection, the [aggregation accumulator operators]({{< docsref "reference/operator/aggregation/group/#accumulator-operator" >}}) are also supported.
272
272
273
273
274
274
## Sorts
@@ -285,7 +285,7 @@ SortDefinition<BsonDocument> sort = new BsonDocument("x", 1);
285
285
286
286
Both of these will render the sort `{ x: 1 }`.
287
287
288
-
### Sort Definition Builder
288
+
### Sort Definition Builder
289
289
290
290
_See the [tests]({{< testref "MongoDB.Driver.Tests/SortDefinitionBuilderTests.cs" >}}) for examples._
291
291
@@ -303,11 +303,11 @@ Given the following class:
303
303
```csharp
304
304
classWidget
305
305
{
306
-
[BsonElement("x")]
307
-
publicintX { get; set; }
306
+
[BsonElement("x")]
307
+
publicintX { get; set; }
308
308
309
-
[BsonElement("y")]
310
-
publicintY { get; set; }
309
+
[BsonElement("y")]
310
+
publicintY { get; set; }
311
311
}
312
312
```
313
313
@@ -329,7 +329,7 @@ var sort = builder.Ascending("x").Descending("y");
329
329
330
330
## Updates
331
331
332
-
[`UpdateDefinition<TDocument>`]({{< apiref "T_MongoDB_Driver_UpdateDefinition_1" >}}) defines how to render a valid update document. It is implicity convertible from both a JSON string as well as a [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}).
332
+
[`UpdateDefinition<TDocument>`]({{< apiref "T_MongoDB_Driver_UpdateDefinition_1" >}}) defines how to render a valid update document. It is implicity convertible from both a JSON string as well as a [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}).
333
333
334
334
```csharp
335
335
// invocation
@@ -343,7 +343,7 @@ UpdateDefinition<BsonDocument> update = new BsonDocument("$set", new BsonDocumen
343
343
Both of these will render the update `{ $set: { x: 1 } }`.
344
344
345
345
346
-
### Update Definition Builder
346
+
### Update Definition Builder
347
347
348
348
_See the [tests]({{< testref "MongoDB.Driver.Tests/UpdateDefinitionBuilderTests.cs" >}}) for examples._
349
349
@@ -403,7 +403,7 @@ IndexKeysDefinition<BsonDocument> keys = new BsonDocument("x", 1);
403
403
Both of these will render the keys `{ x: 1 }`.
404
404
405
405
406
-
### Index Keys Definition Builder
406
+
### Index Keys Definition Builder
407
407
408
408
_See the [tests]({{< testref "MongoDB.Driver.Tests/IndexKeysDefinitionBuilderTests.cs" >}}) for examples._
409
409
@@ -421,11 +421,11 @@ Given the following class:
421
421
```csharp
422
422
classWidget
423
423
{
424
-
[BsonElement("x")]
425
-
publicintX { get; set; }
424
+
[BsonElement("x")]
425
+
publicintX { get; set; }
426
426
427
-
[BsonElement("y")]
428
-
publicintY { get; set; }
427
+
[BsonElement("y")]
428
+
publicintY { get; set; }
429
429
}
430
430
```
431
431
@@ -468,4 +468,4 @@ var keys = builder.Wildcard();
0 commit comments