Skip to content

Commit 0bfd7a9

Browse files
committed
updating docs from master
1 parent ce9dbce commit 0bfd7a9

File tree

12 files changed

+744
-83
lines changed

12 files changed

+744
-83
lines changed

Docs/landing/data/releases.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
current = "2.0.1"
1+
current = "2.0.0"
22
[[versions]]
3-
version = "2.0.1"
3+
version = "2.0.0"
44
status = "rc"
55
docs = "http://mongodb.github.io/mongo-csharp-driver/2.0/"
66
api = "http://api.mongodb.org/csharp/2.0"
@@ -16,25 +16,25 @@ current = "2.0.1"
1616
package = "MongoDB.Driver"
1717
description = "The driver."
1818
dependencies = ".NET Core Driver,.NET BSON Library"
19-
versions = "2.0.1"
19+
versions = "2.0.0"
2020

2121
[[drivers]]
2222
name = ".NET Core Driver"
2323
package = "MongoDB.Driver.Core"
2424
description = "The core driver."
2525
dependencies = ".NET BSON Library"
26-
versions = "2.0.1"
26+
versions = "2.0.0"
2727

2828
[[drivers]]
2929
name = ".NET BSON Library"
3030
package = "MongoDB.Bson"
3131
description = "The BSON library."
3232
dependencies = ""
33-
versions = "2.0.1"
33+
versions = "2.0.0"
3434

3535
[[drivers]]
3636
name = ".NET Legacy Driver"
3737
package = "mongocsharpdriver"
3838
description = "The legacy driver."
3939
dependencies = ".NET Driver,.NET Core Driver,.NET BSON Library"
40-
versions = "2.0.1,1.10.0"
40+
versions = "2.0.0,1.10.0"

Docs/reference/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ canonifyurls = false
1010
[[menu.main]]
1111
name = "API Documentation"
1212
pre = "<i class='fa fa-file-text-o'></i>"
13-
weight = 90
13+
weight = 800
1414
identifier = "apiDocs"
1515
url = "http://api.mongodb.org/csharp/2.0"
1616

1717
[[menu.main]]
1818
name = "Source Code"
1919
pre = "<i class='fa fa-github'></i>"
20-
weight = 90
20+
weight = 900
2121
identifier = "githubLink"
2222
url = "https://github.com/mongodb/mongo-csharp-driver/tree/master"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
+++
2+
date = "2015-03-17T15:36:56Z"
3+
draft = false
4+
title = "Exporting JSON"
5+
[menu.main]
6+
parent = "Examples"
7+
identifier = "Exporting JSON"
8+
weight = 10
9+
pre = "<i class='fa'></i>"
10+
+++
11+
12+
## Exporting JSON
13+
14+
The .NET BSON library supports writing JSON documents with the [`JsonWriter`]({{< apiref "T_MongoDB_Bson_IO_JsonWriter" >}}) class.
15+
16+
The program below will export all documents from a collection to a file with one document per line.
17+
18+
Given the collection's contents:
19+
20+
```bash
21+
> db.mydata.find()
22+
{ "_id" : ObjectId("5513306a2dfd32ffd580e323"), "x" : 1.0 }
23+
{ "_id" : ObjectId("5513306c2dfd32ffd580e324"), "x" : 2.0 }
24+
{ "_id" : ObjectId("5513306e2dfd32ffd580e325"), "x" : 3.0 }
25+
{ "_id" : ObjectId("551330712dfd32ffd580e326"), "x" : 4.0 }
26+
```
27+
28+
And the program:
29+
30+
```csharp
31+
using MongoDB.Bson;
32+
using MongoDB.Bson.IO;
33+
using MongoDB.Bson.Serialization;
34+
using MongoDB.Driver;
35+
36+
// ...
37+
38+
string outputFileName; // initialize to the output file
39+
IMongoCollection<BsonDocument> collection; // initialize to the collection to read from
40+
41+
using (var streamWriter = new StreamWriter(outputFileName))
42+
{
43+
await collection.Find(new BsonDocument())
44+
.ForEachAsync(async (document) =>
45+
{
46+
using (var stringWriter = new StringWriter())
47+
using (var jsonWriter = new JsonWriter(stringWriter))
48+
{
49+
var context = BsonSerializationContext.CreateRoot(jsonWriter);
50+
collection.DocumentSerializer.Serialize(context, document);
51+
var line = stringWriter.ToString();
52+
await streamWriter.WriteLineAsync(line);
53+
}
54+
});
55+
}
56+
```
57+
58+
The output file should look this:
59+
60+
```json
61+
{ "_id" : ObjectId("5513306a2dfd32ffd580e323"), "x" : 1.0 }
62+
{ "_id" : ObjectId("5513306c2dfd32ffd580e324"), "x" : 2.0 }
63+
{ "_id" : ObjectId("5513306e2dfd32ffd580e325"), "x" : 3.0 }
64+
{ "_id" : ObjectId("551330712dfd32ffd580e326"), "x" : 4.0 }
65+
```

Docs/reference/content/examples/import_export.md

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
+++
2+
date = "2015-03-17T15:36:56Z"
3+
draft = false
4+
title = "Importing JSON"
5+
[menu.main]
6+
parent = "Examples"
7+
identifier = "Importing JSON"
8+
weight = 20
9+
pre = "<i class='fa'></i>"
10+
+++
11+
12+
## Importing JSON
13+
14+
The .NET BSON library supports reading JSON documents with the [`JsonReader`]({{< apiref "T_MongoDB_Bson_IO_JsonReader" >}}) class.
15+
16+
The program below will import all documents from a file with one document per line into the collection.
17+
18+
Given the input file's contents:
19+
20+
```json
21+
{ "_id" : ObjectId("5513306a2dfd32ffd580e323"), "x" : 1.0 }
22+
{ "_id" : ObjectId("5513306c2dfd32ffd580e324"), "x" : 2.0 }
23+
{ "_id" : ObjectId("5513306e2dfd32ffd580e325"), "x" : 3.0 }
24+
{ "_id" : ObjectId("551330712dfd32ffd580e326"), "x" : 4.0 }
25+
```
26+
27+
And the program:
28+
29+
```csharp
30+
using MongoDB.Bson;
31+
using MongoDB.Bson.IO;
32+
using MongoDB.Bson.Serialization;
33+
using MongoDB.Driver;
34+
35+
// ...
36+
37+
string inputFileName; // initialize to the input file
38+
IMongoCollection<BsonDocument> collection; // initialize to the collection to write to.
39+
40+
using (var streamReader = new StreamReader(inputFileName))
41+
{
42+
string line;
43+
while ((line = await streamReader.ReadLineAsync()) != null)
44+
{
45+
using (var jsonReader = new JsonReader(line))
46+
{
47+
var context = BsonDeserializationContext.CreateRoot(jsonReader);
48+
var document = collection.DocumentSerializer.Deserialize(context);
49+
await collection.InsertOneAsync(document);
50+
}
51+
}
52+
}
53+
```
54+
55+
The collection's contents should look like this:
56+
57+
```bash
58+
> db.mydata.find()
59+
{ "_id" : ObjectId("5513306a2dfd32ffd580e323"), "x" : 1.0 }
60+
{ "_id" : ObjectId("5513306c2dfd32ffd580e324"), "x" : 2.0 }
61+
{ "_id" : ObjectId("5513306e2dfd32ffd580e325"), "x" : 3.0 }
62+
{ "_id" : ObjectId("551330712dfd32ffd580e326"), "x" : 4.0 }
63+
```

Docs/reference/content/examples/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++
22
date = "2015-03-17T15:36:56Z"
3-
draft = true
3+
draft = false
44
title = "Examples"
55
[menu.main]
66
weight = 90
@@ -12,4 +12,8 @@ title = "Examples"
1212

1313
A number of examples have been compiled to show a more thorough usage of certain features and how they interact.
1414

15-
- [Importing and Exporting]({{< relref "examples\import_export.md" >}}): Sample implementations of [mongoimport]({{< docsref "reference/program/mongoimport/" >}}) and [mongoexport]({{< docsref "reference/program/mongoexport/" >}}).
15+
- [Importing JSON]({{< relref "examples\importing_json.md" >}}): How to read JSON from a file and insert it into a collection.
16+
- [Exporting JSON]({{< relref "examples\exporting_json.md" >}}): How to read data from a collection and export it to a JSON file.
17+
- [Mixing Static and Dynamic Data]({{< relref "examples\mixing_static_and_dynamic.md" >}}): How to have both static and dynamic data inside your classes.
18+
- [Using Tailable Cursors]({{< relref "examples\tailable_cursor.md" >}}): How to use a tailable cursor.
19+
- [Managing Users]({{< relref "examples\user_management.md" >}}): How to manage users.

0 commit comments

Comments
 (0)