Skip to content

Commit 69639c6

Browse files
committed
CR Changes
1 parent 63e29f0 commit 69639c6

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

Docs/reference/content/reference/bson/mapping/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ BsonClassMap.RegisterClassMap<Employee>(cm =>
620620

621621
#### Enums
622622

623-
Another case that deserves mention is enumerations. Enumerations are, by default, represented as their base value. In other words, a plain enum will be represented as an integer value. However, it is possible to instruct the driver to represent an enum as a string.
623+
Another case that deserves mention is enums. Enums are, by default, represented as their underlying value. In other words, a plain enum will be represented as an integer value. However, it is possible to instruct the driver to represent an enum as a string.
624624

625625
```csharp
626626
public enum Color

Docs/reference/content/reference/driver/crud/writing.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var result = await collection.DeleteManyAsync(filter);
9292

9393
## Find And Modify
9494

95-
There are a certain class of operations using the [findAndModify command]({{< docsref "reference/command/findAndModify/" >}}) from the server. This command will perform some operation on the document and return the document either before or after the modification takes place. By default, the document is returned before the modification takes place.
95+
There are a certain class of operations using the [findAndModify command]({{< docsref "reference/command/findAndModify/" >}}) from the server. This command will perform some operation on the document and return either the original version of the document as it was before the operation, or the new version of the document as it became after the operation. By default, the original version of the document is returned.
9696

9797
### FindOneAndDelete
9898

@@ -102,7 +102,10 @@ A single document can be deleted atomically using [`FindOneAndDeleteAsync`]({{<
102102
var filter = new BsonDocument("FirstName", "Jack");
103103
var result = await collection.FindOneAndDeleteAsync(filter);
104104

105-
Assert(result["FirstName"] == "Jack"); // will be true if a document was found.
105+
if (result != null)
106+
{
107+
Assert(result["FirstName"] == "Jack");
108+
}
106109
```
107110

108111
The above will find a document where the `FirstName` is `Jack` and delete it. It will then return the document that was just deleted.
@@ -118,7 +121,10 @@ var replacementDocument = new BsonDocument("FirstName", "John");
118121

119122
var result = await collection.FindOneAndReplaceAsync(filter, doc);
120123

121-
Assert(result["FirstName"] == "Jack"); // will be true if a document was found.
124+
if (result != null)
125+
{
126+
Assert(result["FirstName"] == "Jack");
127+
}
122128
```
123129

124130
The above will find a document where the `FirstName` is `Jack` and replace it with `replacementDocument`. It will then return the document that was replaced.
@@ -133,7 +139,10 @@ var update = Builders<BsonDocument>.Update.Set("FirstName", "John");
133139

134140
var result = await collection.FindOneAndUpdateAsync(filter, update);
135141

136-
Assert(result["FirstName"] == "Jack"); // will be true if a document was found.
142+
if (result != null)
143+
{
144+
Assert(result["FirstName"] == "Jack");
145+
}
137146
```
138147

139148
The above will find a document where the `FirstName` is `Jack` and set its `FirstName` field to `John`. It will then return the document that was replaced.
@@ -145,21 +154,24 @@ Each of the 3 operations has certain options available.
145154

146155
#### ReturnDocument
147156

148-
For Replacing and Updating, the [`ReturnDocument`]({{< apiref "T_MongoDB_Driver_ReturnDocument" >}}) enum can be provided. It allows you to return the document after the modification has taken place. The default is `Before`.
157+
For Replacing and Updating, the [`ReturnDocument`]({{< apiref "T_MongoDB_Driver_ReturnDocument" >}}) enum can be provided. It allows you to choose which version of the document to return, either the original version as it was before the operation, or the modified version as it became after the operation.
149158

150159
For example:
151160

152161
```csharp
153162
var filter = new BsonDocument("FirstName", "Jack");
154163
var update = Builders<BsonDocument>.Update.Set("FirstName", "John");
155164

156-
var options = new FindOneAndUpdateOptions<BsonDocument, BsonDocument>
165+
var options = new FindOneAndUpdateOptions<BsonDocument>
157166
{
158-
ReturnDocument = ReturnDocument.After
167+
ReturnDocument = ReturnDocument.After
159168
};
160169
var result = await collection.FindOneAndUpdateAsync(filter, update, options);
161170

162-
Assert(result["FirstName"] == "John"); // will be true if a document was found.
171+
if (result != null)
172+
{
173+
Assert(result["FirstName"] == "John");
174+
}
163175
```
164176

165177
#### Projection
@@ -168,7 +180,7 @@ A projection can be provided to shape the result. The easiest way to build the p
168180

169181
#### Sort
170182

171-
Since only a single document is selected, for filters that could result in multiple choices, a sort should be provided and the first document will be selected.
183+
Since only a single document is selected, for filters that could result in multiple choices, a sort should be provided and the first document in the sort order will be the one modified.
172184

173185
#### IsUpsert
174186

Docs/reference/content/upgrading.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ As 2.0 is a major revision, there are some breaking changes when coming from the
3535
- [CSHARP-979](https://jira.mongodb.org/browse/CSHARP-979): `MongoConnectionStringBuilder` has been removed. Use the documented mongodb connection string format and/or `MongoUrlBuilder`.
3636
- `MongoServer` is a deprecated class. Anyone using `MongoClient.GetServer()` will encounter a deprecation warning and, depending on how your build is setup, may receive an error. It is still safe to use this API until your code is ported to the new API. *Note that this API requires the use of the [mongocsharpdriver](http://nuget.org/packages/mongocsharpdriver) to include the legacy API.
3737
- [CSHARP-1043](https://jira.mongodb.org/browse/CSHARP-1043) and [CSHARP-1044](https://jira.mongodb.org/browse/CSHARP-1044): `ReadPreference` and `WriteConcern` were rewritten. These classes are now immutable. Any current application code that sets values on these classes will no longer function. Instead, you should use the With method to alter a `ReadPreference` or `WriteConcern`.
38-
39-
``` csharp
40-
var writeConcern = myCurrentWriteConcern.With(journal: true);
41-
```
38+
39+
``` csharp
40+
var writeConcern = myCurrentWriteConcern.With(journal: true);
41+
```
4242

4343
## Migrating
4444

@@ -48,13 +48,13 @@ Below are some common actions in the old API and their counterpart in the new AP
4848

4949
_[More information.]({{< relref "reference\driver\definitions.md" >}})_
5050

51-
The old builders (Query, Update, etc...) have all be replaced with Builders<T>.Filter, Builders<T>.Update, etc...
51+
The old builders (`Query`, `Update`, etc...) have all been replaced by `Builders<T>.Filter`, `Builders<T>.Update`, etc...
5252

5353
```csharp
5454
// old API
5555
var query = Query.And(
56-
Query<Person>.EQ(x => x.FirstName, "Jack"),
57-
Query<Person>.LT(x => x.Age, 21));
56+
Query<Person>.EQ(x => x.FirstName, "Jack"),
57+
Query<Person>.LT(x => x.Age, 21));
5858

5959
// new API
6060
var builder = Builders<Person>.Filter;
@@ -64,20 +64,20 @@ var filter = builder.Eq(x => x.FirstName, "Jack") & builder.Lt(x => x.Age, 21);
6464
```csharp
6565
// old API
6666
var update = Update.Combine(
67-
Update<Person>.Set(x => x.LastName, "McJack"),
68-
Update<Person>.Inc(x => x.Age, 1));
67+
Update<Person>.Set(x => x.LastName, "McJack"),
68+
Update<Person>.Inc(x => x.Age, 1));
6969

7070
// new API
7171
var update = Builders<Person>.Update
72-
.Set(x => x.LastName, "McJack")
73-
.Inc(x => x.Age, 1);
72+
.Set(x => x.LastName, "McJack")
73+
.Inc(x => x.Age, 1);
7474
```
7575

7676
### Finding All Documents
7777

7878
_[More information.]({{< relref "reference\driver\crud\reading.md#finding-documents" >}})_
7979

80-
To find all documents, you must specify an empty filter.
80+
To match all documents, you must specify an empty filter.
8181

8282
```csharp
8383
// old API
@@ -91,14 +91,14 @@ var list = await collection.Find(new BsonDocument()).ToListAsync();
9191

9292
_[More information.]({{< relref "reference\driver\crud\reading.md#single-results" >}})_
9393

94-
To find all documents, you must specify an empty filter.
94+
To match all documents, you must specify an empty filter.
9595

9696
```csharp
9797
// old API
98-
var doc = collection.FindOne();
98+
var document = collection.FindOne();
9999

100100
// new API
101-
var doc = await collection.Find(new BsonDocument()).FirstOrDefaultAsync();
101+
var document = await collection.Find(new BsonDocument()).FirstOrDefaultAsync();
102102
```
103103

104104
### Iteration
@@ -109,30 +109,30 @@ You cannot iterate synchronously using a foreach loop without first getting a li
109109

110110
```csharp
111111
// old API
112-
foreach(var doc in collection.Find(new QueryDocument("Name", "Jack")))
112+
foreach (var document in collection.Find(new QueryDocument("Name", "Jack")))
113113
{
114-
// do something
114+
// do something
115115
}
116116

117117
// new API
118118
await collection.Find(new BsonDocument("Name", "Jack"))
119-
.ForEachAsync(doc =>
120-
{
121-
// do something
122-
});
119+
.ForEachAsync(document =>
120+
{
121+
// do something
122+
});
123123

124124
await collection.Find(new BsonDocument("Name", "Jack"))
125-
.ForEachAsync(async doc =>
126-
{
127-
// do something with await
128-
});
125+
.ForEachAsync(async document =>
126+
{
127+
// do something with await
128+
});
129129
```
130130

131131
### Counting All Documents
132132

133133
_[More information.]({{< relref "reference\driver\crud\reading.md#counting-documents" >}})_
134134

135-
To find all documents, you must specify an empty filter.
135+
To match all documents, you must specify an empty filter.
136136

137137
```csharp
138138
// old API
@@ -151,20 +151,20 @@ You can still use attributes as you have done before. To set the representation
151151
```csharp
152152
class Test
153153
{
154-
public char RepresentAsInt32 { get; set; }
154+
public char RepresentAsInt32 { get; set; }
155155
}
156156

157157
// old API
158158
BsonClassMap.RegisterClassMap<Person>(cm =>
159159
{
160-
// snip...
161-
cm.MapMember(x => x.RepresentAsInt32).SetRepresentation(BsonType.Int32);
160+
// snip...
161+
cm.MapMember(x => x.RepresentAsInt32).SetRepresentation(BsonType.Int32);
162162
});
163163

164164
// new API
165165
BsonClassMap.RegisterClassMap<Person>(cm =>
166166
{
167-
// snip...
168-
cm.MapMember(x => x.RepresentAsInt32).SetSerializer(new CharSerializer(BsonType.Int32));
167+
// snip...
168+
cm.MapMember(x => x.RepresentAsInt32).SetSerializer(new CharSerializer(BsonType.Int32));
169169
});
170170
```

0 commit comments

Comments
 (0)