Skip to content

Commit 751e4d3

Browse files
Merge branch 'tech-review'
2 parents 227a516 + 15b0746 commit 751e4d3

File tree

90 files changed

+1852
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1852
-817
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
# System
1616

17-
.DS_Store
17+
.DS_Store

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ The MongoDB Documentation Project is governed by the terms of the
2121
`MongoDB Contributor Agreement
2222
<https://www.mongodb.com/legal/contributor-agreement>`_.
2323

24-
-- The MongoDB Docs Team
24+
-- The MongoDB Docs Team

config/intersphinx.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ path: python2.inv
66
name: mongodb
77
url: https:/www.mongodb.com/docs/manual/
88
path: mongodb.inv
9-
...

snooty.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name = "csharp"
22
title = "C#/.NET"
33
toc_landing_pages = [
4-
"/fundamentals/connection",
5-
"/fundamentals/crud",
6-
"/usage-examples",
7-
"/fundamentals",
4+
"/fundamentals/connection",
5+
"/fundamentals/crud",
6+
"/usage-examples",
7+
"/fundamentals",
88
]
99

1010
intersphinx = [
11-
"https://www.mongodb.com/docs/manual/objects.inv",
12-
"https://www.mongodb.com/docs/drivers/objects.inv",
13-
"https://www.mongodb.com/docs/atlas/objects.inv",
11+
"https://www.mongodb.com/docs/manual/objects.inv",
12+
"https://www.mongodb.com/docs/drivers/objects.inv",
13+
"https://www.mongodb.com/docs/atlas/objects.inv",
1414
]
1515
sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"
1616

@@ -30,7 +30,7 @@ version = "v{+version-number+}"
3030
example = "https://raw.githubusercontent.com/mongodb/docs-csharp/{+docs-branch+}/source/includes/usage-examples/code-examples"
3131
stable-api = "Stable API"
3232
api-root = "https://mongodb.github.io/mongo-csharp-driver/{+version-number+}/apidocs/html"
33-
bool-data-type = "``bool``"
34-
string-data-type = "``str``"
35-
int-data-type = "``int``"
33+
bool-data-type = "``boolean``"
34+
string-data-type = "``string``"
35+
int-data-type = "``integer``"
3636
not-available = "N/A"

source/faq.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ To resolve this issue, try the following steps:
115115
can severely affect your application performance. Before
116116
considering changes to this setting, address the concurrency problems
117117
in your application.
118-
118+
119+
.. _csharp-faq-unsupported-expressions:
120+
119121
Why are Certain LINQ or Builder Expressions Unsupported?
120122
--------------------------------------------------------
121123

@@ -126,8 +128,8 @@ always possible for the following reasons:
126128
equivalent MongoDB representation. For example, {+lang-framework+} and MongoDB have
127129
different semantics around collations.
128130
#. The driver does not support a particular transformation from LINQ or
129-
Builder expression into a server query. This may happen because the
130-
provided query is too complicated or because a feature has not been
131+
Builder expression into MQL (MongoDB Query Language). This may happen because the
132+
provided query has no MQL translation or because a feature has not been
131133
implemented yet in the driver.
132134

133135
If you receive an ``Unsupported filter ...`` or ``Expression not
@@ -138,6 +140,9 @@ steps:
138140
<https://mongodb.github.io/mongo-csharp-driver/2.17/reference/driver/crud/linq3/>`__
139141
provider. The LINQ3 provider contains many fixes and new features
140142
over the LINQ2 provider.
143+
#. Use the `MongoDB Analyzer
144+
<https://www.mongodb.com/docs/mongodb-analyzer/current/>`__ to analyze your
145+
expressions.
141146
#. Try to simplify your query where possible.
142147
#. Provide a query as a ``BsonDocument`` or JSON string. All driver
143148
definition classes such as ``FilterDefinition``,

source/fundamentals/authentication.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ authentication mechanisms, depending on which MongoDB versions your server suppo
7171
.. note::
7272

7373
MongoDB version 4.0 uses SCRAM as the default mechanism, and no longer
74-
supports ``MONGODB-CR``. These versions automatically determine which
75-
version of SCRAM to use.
74+
supports ``MONGODB-CR``.
7675

7776

7877
Select the :guilabel:`Connection String` or :guilabel:`MongoCredential` tab to
@@ -200,6 +199,11 @@ see the corresponding syntax for specifying the ``X.509`` authentication mechani
200199
Server = new MongoServerAddress("<hostname", "<port>"),
201200
};
202201

202+
.. note:: Certificate Type
203+
204+
Your certificate must be a :wikipedia:`PCKS #12<PKCS_12>` type certificate
205+
with a ``.p12`` extension.
206+
203207
.. tip:: Username parameter
204208

205209
The username parameter provided to ``CreateMongoX509Credential`` must

source/fundamentals/builders.txt

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,66 @@ single field path``, in this case using ``Category``:
272272
// Using string-based field names
273273
var keys = builder.Wildcard("Category");
274274

275+
Build an Aggregation Pipeline
276+
-----------------------------
277+
278+
The ``PipelineDefinitionBuilder`` class provides a type-safe interface for
279+
defining an **aggregation pipeline**. An aggregation pipeline is a series of
280+
stages that are used to transform a document. Suppose you want to create a
281+
pipeline that performs the following operations:
282+
283+
- Matches all documents with "spring" in the ``Season`` field
284+
- Sorts the results by the ``Category`` field
285+
- Groups the documents by category and shows the average price and total
286+
available for all documents in that category
287+
288+
Use ``PipelineDefinitionBuilder`` classes to build the pipeline:
289+
290+
.. code-block:: csharp
291+
292+
var sortBuilder = Builders<Flower>.Sort.Ascending(f => f.Category);
293+
var matchFilter = Builders<Flower>.Filter.AnyEq(f => f.Season, "spring");
294+
295+
var pipeline = new EmptyPipelineDefinition<Flower>()
296+
.Match(matchFilter)
297+
.Sort(sortBuilder)
298+
.Group(f => f.Category,
299+
g => new
300+
{
301+
name = g.Key,
302+
avgPrice = g.Average(f => f.Price),
303+
totalAvailable = g.Sum(f => f.Stock)
304+
}
305+
);
306+
307+
The preceding example creates the following pipeline:
308+
309+
.. code-block:: json
310+
311+
[{ "$match" : { "season" : "spring" } }, { "$sort" : { "category" : 1 } }, { "$group" : { "_id" : "$category", "avgPrice" : { "$avg" : "$price" }, "totalAvailable" : { "$sum" : "$stock" } } }]
312+
313+
You can add stages to your pipeline that don't have corresponding type-safe
314+
methods in the ``PipelineDefinitionBuilder`` interface by providing your query
315+
as a ``BsonDocument`` to the `AppendStage() method
316+
<{+api-root+}/M_MongoDB_Driver_PipelineDefinitionBuilder_AppendStage__3.htm>`__.
317+
318+
.. code-block:: csharp
319+
320+
var pipeline = new EmptyPipelineDefinition<BsonDocument>().AppendStage<BsonDocument, BsonDocument, BsonDocument>("{ $set: { field1: '$field2' } }");
321+
322+
.. note::
323+
324+
When using a ``BsonDocument`` to define your pipeline stage, the driver does
325+
not take into account any ``BsonClassMap``, serialization attributes or
326+
serialization conventions. The field names used in the ``BsonDocument`` must
327+
match those stored on the server.
328+
329+
For more information on providing a query as a ``BsonDocument``, see our
330+
:ref:`FAQ page <csharp-faq-unsupported-expressions>`.
331+
332+
To learn more about the Aggregation Pipeline, see the
333+
:manual:`Aggregation Pipeline </core/aggregation-pipeline/>` server manual page.
334+
275335
Additional Information
276336
----------------------
277337

@@ -288,4 +348,5 @@ guide, see the following API Documentation:
288348
- `ProjectionDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_ProjectionDefinitionBuilder_1.htm>`__
289349
- `SortDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_SortDefinitionBuilder_1.htm>`__
290350
- `UpdateDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_UpdateDefinitionBuilder_1.htm>`__
291-
- `IndexKeysDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_IndexKeysDefinitionBuilder_1.htm>`__
351+
- `IndexKeysDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_IndexKeysDefinitionBuilder_1.htm>`__
352+
- `IndexKeysDefinitionBuilder <{+api-root+}/T_MongoDB_Driver_PipelineDefinitionBuilder.htm>`__

source/fundamentals/class-mapping.txt

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ the name of the field in the document to the name of the property in the class.
3131
The type of the property in your class should match the type of the field in
3232
the document. The {+driver-short+} instantiates a serializer based on the
3333
type of the property in your class. If the types don't match when the driver
34-
attempts to serialize the data, the serializer will throw an exception.
34+
attempts to deserialize the data, the serializer throws an exception.
3535

3636
Manually Creating A Class Map
3737
-----------------------------
@@ -55,11 +55,11 @@ class:
5555

5656
.. code-block:: csharp
5757

58-
BsonClassMap.RegisterClassMap<Person>(classmap =>
58+
BsonClassMap.RegisterClassMap<Person>(classMap =>
5959
{
60-
classmap.MapMember(p => p.Name);
61-
classmap.MapMember(p => p.Age);
62-
classmap.MapMember(p => p.Hobbies);
60+
classMap.MapMember(p => p.Name);
61+
classMap.MapMember(p => p.Age);
62+
classMap.MapMember(p => p.Hobbies);
6363
});
6464

6565
.. important::
@@ -73,14 +73,15 @@ register a class map and call the ``AutoMap()`` method before manually
7373
specifying your properties.
7474

7575
In the following code example, the ``AutoMap()`` method maps all properties
76-
of the ``Person`` class except ``Hobbies``, which is mapped manually:
76+
of the ``Person`` class, then manually adjusts the mapping for the ``Hobbies``
77+
field:
7778

7879
.. code-block:: csharp
7980

80-
BsonClassMap.RegisterClassMap<Person>(classmap =>
81+
BsonClassMap.RegisterClassMap<Person>(classMap =>
8182
{
82-
classmap.AutoMap();
83-
classmap.MapMember(p => p.Hobbies);
83+
classMap.AutoMap();
84+
classMap.MapMember(p => p.Hobbies).SetElementName("favorite_hobbies");
8485
});
8586

8687
Customize Class Serialization
@@ -120,10 +121,10 @@ You can also ignore any extra elements when registering a class map:
120121

121122
.. code-block:: csharp
122123

123-
BsonClassMap.RegisterClassMap<Person>(classmap =>
124+
BsonClassMap.RegisterClassMap<Person>(classMap =>
124125
{
125-
classmap.AutoMap();
126-
classmap.SetIgnoreExtraElements(true);
126+
classMap.AutoMap();
127+
classMap.SetIgnoreExtraElements(true);
127128
});
128129

129130
Using Class Discriminators
@@ -152,10 +153,10 @@ You can also specify a discriminator when registering a class map as follows:
152153

153154
.. code-block:: csharp
154155

155-
BsonClassMap.RegisterClassMap<Person>(classmap =>
156+
BsonClassMap.RegisterClassMap<Person>(classMap =>
156157
{
157-
classmap.AutoMap();
158-
classmap.SetDiscriminator("personClass");
158+
classMap.AutoMap();
159+
classMap.SetDiscriminator("personClass");
159160
});
160161

161162
In BSON, discriminators have the field name ``_t``.
@@ -165,7 +166,7 @@ The following example shows how a document from the ``Person`` class with the
165166

166167
.. code-block:: json
167168

168-
{ "_id": "...", "_t": "personClass", "name": "...", "age": "...", "hobbies": [...]}
169+
{ "_id": "...", "_t": "personClass", "Name": "...", "Age": "...", "Hobbies": [...]}
169170

170171
.. TODO: Link to page on polymorphism/discriminators
171172

@@ -175,7 +176,7 @@ Mapping with Constructors
175176
By default, the {+driver-short+} can automatically map a class only if the class has
176177
a constructor with no arguments. If you want the driver to use a constructor that accepts
177178
one or more arguments, you can add the ``BsonConstructor`` attribute to the constructor.
178-
In this case, the driver parses the expression tree to determine how to map the
179+
In this case, the driver the driver examines the types to determine how to map the
179180
constructor arguments to class properties or fields.
180181

181182
When the driver creates a class map for the following ``Person`` class, it will use the
@@ -223,10 +224,10 @@ You can also specify the constructor to use when registering your class map:
223224
}
224225
}
225226

226-
BsonClassMap.RegisterClassMap<Person>(classmap =>
227+
BsonClassMap.RegisterClassMap<Person>(classMap =>
227228
{
228-
classmap.AutoMap();
229-
classmap.MapCreator(p => new Person(p.Name, p.Age));
229+
classMap.AutoMap();
230+
classMap.MapCreator(p => new Person(p.Name, p.Age));
230231
});
231232

232233
Customize Property Serialization
@@ -261,10 +262,10 @@ You can also support extra elements when initializing a class map as follows:
261262

262263
.. code-block:: csharp
263264

264-
BsonClassMap.RegisterClassMap<Person>(classmap =>
265+
BsonClassMap.RegisterClassMap<Person>(classMap =>
265266
{
266-
classmap.AutoMap();
267-
classmap.MapExtraElementsMember(p => p.ExtraElements);
267+
classMap.AutoMap();
268+
classMap.MapExtraElementsMember(p => p.ExtraElements);
268269
});
269270

270271
.. note::
@@ -277,14 +278,15 @@ Dynamically Serialize Properties
277278
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278279

279280
You can use a method to determine whether or not to serialize a property. For
280-
the driver to automatically use the method when serializing, the method must be
281-
named ``ShouldSerialize<property name>``. When the driver sees a method with
282-
this naming convention, it will use the method to determine whether or not to
283-
serialize properties of the provided property name.
281+
the driver to automatically use the method when serializing, you must prefix the
282+
method name with ``ShouldSerialize`` followed by the name of the property that
283+
the method applies to. When the driver sees a method with this naming
284+
convention, it uses that method to determine whether or not to serialize
285+
properties that have the provided property name.
284286

285287
The following example creates a method that only serializes the ``Age`` property
286-
if its value is greater than ``0``. The driver ignores any properties whose
287-
values don't meet this requirement:
288+
if its value is not equal to ``0``. The driver does not serialize any properties
289+
whose values don't meet this requirement:
288290

289291
.. code-block:: csharp
290292

@@ -296,19 +298,19 @@ values don't meet this requirement:
296298

297299
public bool ShouldSerializeAge()
298300
{
299-
return Age > 0;
301+
return Age != 0;
300302
}
301303
}
302304

303305
You can also specify the method while registering a class map:
304306

305307
.. code-block:: csharp
306308

307-
BsonClassMap.RegisterClassMap<Employee>(classmap =>
309+
BsonClassMap.RegisterClassMap<Employee>(classMap =>
308310
{
309-
classmap.AutoMap();
310-
classmap.MapMember(p => c.Age).SetShouldSerializeMethod(
311-
obj => ((Person) obj).Age > 0
311+
classMap.AutoMap();
312+
classMap.MapMember(p => c.Age).SetShouldSerializeMethod(
313+
obj => ((Person) obj).Age != 0
312314
);
313315
});
314316

0 commit comments

Comments
 (0)