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/examples/exporting_json.md
+32-2Lines changed: 32 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ title = "Exporting JSON"
13
13
14
14
The .NET BSON library supports writing JSON documents with the [`JsonWriter`]({{< apiref "T_MongoDB_Bson_IO_JsonWriter" >}}) class.
15
15
16
-
The program below will export all documents from a collection to a file with one document per line.
16
+
The programs below will export all documents from a collection to a file with one document per line. There are two versions of the program, one using the synchronous API and the other using the asynchronous API.
17
17
18
18
Given the collection's contents:
19
19
@@ -25,7 +25,37 @@ Given the collection's contents:
Copy file name to clipboardExpand all lines: Docs/reference/content/examples/importing_json.md
+30-2Lines changed: 30 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ title = "Importing JSON"
13
13
14
14
The .NET BSON library supports reading JSON documents with the [`JsonReader`]({{< apiref "T_MongoDB_Bson_IO_JsonReader" >}}) class.
15
15
16
-
The program below will import all documents from a file with one document per line into the collection.
16
+
The programs below will import all documents from a file with one document per line into the collection. There are two versions of the program, one using the synchronous API and the other using the asynchronous API.
17
17
18
18
Given the input file's contents:
19
19
@@ -24,7 +24,35 @@ Given the input file's contents:
24
24
{ "_id" : ObjectId("551330712dfd32ffd580e326"), "x" : 4.0 }
25
25
```
26
26
27
-
And the program:
27
+
And the synchronous version of the program::
28
+
29
+
```csharp
30
+
usingMongoDB.Bson;
31
+
usingMongoDB.Bson.IO;
32
+
usingMongoDB.Bson.Serialization;
33
+
usingMongoDB.Driver;
34
+
35
+
// ...
36
+
37
+
stringinputFileName; // initialize to the input file
38
+
IMongoCollection<BsonDocument>collection; // initialize to the collection to write to.
39
+
40
+
using (varstreamReader=newStreamReader(inputFileName))
Copy file name to clipboardExpand all lines: Docs/reference/content/examples/tailable_cursor.md
+49-6Lines changed: 49 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,58 @@ title = "Using a Tailable Cursor"
13
13
14
14
MongoDB offers the option to watch a [capped collection]({{< docsref "manual/core/capped-collections/" >}}) for changes using a [tailable cursor]({{< docsref "manual/tutorial/create-tailable-cursor/" >}}).
15
15
16
-
The code below "tails" the capped collection and outputs documents to the console as they are added. The method also handles the possibility of a dead cursor by tracking the field `insertDate`. New documents are added with increasing values of `insertDate`.
16
+
The code below "tails" a capped collection and outputs documents to the console as they are added. The method also handles the possibility of a dead cursor by tracking the field `insertDate`. New documents are added with increasing values of `insertDate`.
17
17
18
18
{{% note %}}Even though we are using [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}) below, it is possible to use an application defined class by replacing the [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}) references with that of your application defined class.{{% /note %}}
19
19
20
+
This version of the code uses the synchronous API to tail the capped collection:
{{% note %}}If multiple documents might have the exact same insert date, then using the above logic might cause you to miss some documents in the event that the cursor gets restarted. To solve this,
61
-
you could track all the documents you've seen by their identifiers for the same `lastValue` and ignore them in the callback. In addition, you would need to change the `$gt` condition to `$gte`{{% /note %}}.
104
+
you could track all the documents you've seen by their identifiers for the same `lastInsertDate` and ignore them when restarting the tailable cursor. In addition, you would need to change the `$gt` condition to `$gte`{{% /note %}}.
Copy file name to clipboardExpand all lines: Docs/reference/content/examples/user_management.md
+50-28Lines changed: 50 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ title = "Managing Users"
11
11
12
12
## How to Manage Users
13
13
14
-
While MongoDB supports many user management commands, the driver does not have any helpers for them because users are generally managed from the [MongoDB shell]({{< docsref "reference/mongo-shell/" >}}). However, it is still possible to manage users from the driver by using the [`IMongoDatabase.RunCommandAsync`]({{< apiref "M_MongoDB_Driver_IMongoDatabase_RunCommandAsync__1" >}}) method.
14
+
While MongoDB supports many user management commands, the driver does not have any helpers for them because users are generally managed from the [MongoDB shell]({{< docsref "reference/mongo-shell/" >}}). However, it is still possible to manage users from the driver by using the [`RunCommand`]({{< apiref "M_MongoDB_Driver_IMongoDatabase_RunCommand__1" >}}) or [`RunCommandAsync`]({{< apiref "M_MongoDB_Driver_IMongoDatabase_RunCommandAsync__1" >}}) methods.
15
15
16
16
17
17
## Listing Users
@@ -24,7 +24,12 @@ var db = client.GetDatabase("products");
24
24
25
25
// construct the usersInfo command
26
26
varcommand=newBsonDocument("usersInfo", 1);
27
-
27
+
```
28
+
```csharp
29
+
// Run the command. If it fails, an exception will be thrown.
30
+
varresult=db.RunCommand<BsonDocument>(command);
31
+
```
32
+
```csharp
28
33
// Run the command. If it fails, an exception will be thrown.
0 commit comments