Skip to content

Commit abc27f3

Browse files
committed
CSHARP-1395: Add links to GridFS docs and other code review changes.
1 parent 5fee8a7 commit abc27f3

File tree

6 files changed

+70
-87
lines changed

6 files changed

+70
-87
lines changed

Docs/reference/content/reference/gridfs/deletingandrenamingfiles.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
date = "2015-09-41T00:00:00Z"
2+
date = "2015-09-14T00:00:00Z"
33
draft = false
44
title = "Deleting and Renaming Files"
55
[menu.main]
@@ -15,9 +15,9 @@ These methods allow you to delete or rename GridFS files.
1515

1616
### Deleting a single file
1717

18-
The DeleteAsync method is used to delete a single file identified by its Id.
18+
The [`DeleteAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_DeleteAsync_1" >}}) method is used to delete a single file identified by its Id.
1919

20-
```
20+
```csharp
2121
IGridFSBucket bucket;
2222
ObjectId id;
2323

@@ -26,21 +26,21 @@ await bucket.DeleteAsync(id);
2626

2727
### Dropping an entire GridFS bucket
2828

29-
If you want to drop an entire GridFS bucket at once use the DropAsync method.
29+
If you want to drop an entire GridFS bucket at once use the [`DropAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_DropAsync" >}}) method.
3030

31-
```
31+
```csharp
3232
IGridFSBucket bucket;
3333

3434
await bucket.DropAsync();
3535
```
3636

37-
The "fs.files" collection will be dropped first, followed by the "fs.chunks" collection. This is the fastest way to delete all files stored in a GridFS bucket at once.
37+
{{% note %}}The "fs.files" collection will be dropped first, followed by the "fs.chunks" collection. This is the fastest way to delete all files stored in a GridFS bucket at once.{{% /note %}}
3838

3939
### Renaming a single file
4040

41-
The RenameAsync method is used to rename a single file identified by its Id.
41+
The [`RenameAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_RenameAsync_1" >}}) method is used to rename a single file identified by its Id.
4242

43-
```
43+
```csharp
4444
IGridFSBucket bucket;
4545
ObjectId id;
4646
string newFilename;
@@ -50,9 +50,9 @@ await bucket.RenameAsync(id, newFilename);
5050

5151
### Renaming all revisions of a file
5252

53-
If you want to rename all revisions of a file you first use FindAsync to find their ids and then call RenameAsync in a loop to rename them one at a time.
53+
If you want to rename all revisions of a file you first use [`FindAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_FindAsync" >}}) to find their ids and then call [`RenameAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_RenameAsync_1" >}}) in a loop to rename them one at a time.
5454

55-
```
55+
```csharp
5656
IGridFSBucket bucket;
5757
ObjectId id;
5858
string oldFilename;

Docs/reference/content/reference/gridfs/downloadingfiles.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
date = "2015-09-41T00:00:00Z"
2+
date = "2015-09-14T00:00:00Z"
33
draft = false
44
title = "Downloading Files"
55
[menu.main]
@@ -13,14 +13,14 @@ title = "Downloading Files"
1313

1414
There are several ways to download a file from GridFS. The two main approaches are:
1515

16-
1. The driver downloads a file as a byte array or by writing the contents to a Stream provided by the application
17-
2. The driver supplies a Stream object that the application can read the contents from
16+
1. The driver downloads a file as a byte array or by writing the contents to a [`Stream`]({{< msdnref "system.io.stream" >}}) provided by the application
17+
2. The driver supplies a [`Stream`]({{< msdnref "system.io.stream" >}}) object that the application can read the contents from
1818

1919
### Downloading as a byte array
2020

2121
This is the easiest way to download a file from GridFS, assuming that the file is small enough for the entire contents to be held in memory at once.
2222

23-
```
23+
```csharp
2424
IGridFSBucket bucket;
2525
ObjectId id;
2626

@@ -29,23 +29,25 @@ var bytes = await bucket.DownloadAsBytesAsync(id);
2929

3030
### Downloading to a Stream
3131

32-
If you don't want to hold the entire contents of the downloaded file in memory at once, you can have the driver write the contents of the file to a Stream provided by the application.
32+
If you don't want to hold the entire contents of the downloaded file in memory at once, you can have the driver write the contents of the file to a [`Stream`]({{< msdnref "system.io.stream" >}}) provided by the application.
3333

34-
```
34+
```csharp
3535
IGridFSBucket bucket;
3636
ObjectId id;
3737
Stream destination;
3838

3939
await bucket.DownloadToStreamAsync(id, destination);
4040
```
4141

42-
The driver will download the contents of the GridFS file and write them to the destination Stream. The driver begins writing the contents at the current position of the Stream, and does **not** close the Stream when it is done. The Stream is owned by the application and it is up to the application to close the Stream when it is ready to do so.
42+
The driver will download the contents of the GridFS file and write them to the destination [`Stream`]({{< msdnref "system.io.stream" >}}). The driver begins writing the contents at the current position of the [`Stream`]({{< msdnref "system.io.stream" >}}).
43+
44+
{{% note class="important" %}}The driver does **not** close the [`Stream`]({{< msdnref "system.io.stream" >}}) when it is done. The [`Stream`]({{< msdnref "system.io.stream" >}}) is owned by the application and it is up to the application to close the [`Stream`]({{< msdnref "system.io.stream" >}}) when it is ready to do so.{{% /note %}}
4345

4446
### Downloading from a Stream
4547

46-
In some cases it the application might prefer to read the contents of the GridFS file from a Stream.
48+
In some cases the application might prefer to read the contents of the GridFS file from a [`Stream`]({{< msdnref "system.io.stream" >}}).
4749

48-
```
50+
```csharp
4951
IGridFSBucket bucket;
5052
ObjectId id;
5153

@@ -56,25 +58,25 @@ using (var stream = await bucket.OpenDownloadStreamAsync(id))
5658
}
5759
```
5860

59-
The Stream object returned by OpenDownloadStreamAsync is actually a GridFSDownloadStream (a subclass of Stream), which has the following additional members in addition to those found in Stream:
61+
The [`Stream`]({{< msdnref "system.io.stream" >}}) object returned by [`OpenDownloadStreamAsync`]({{< apiref "M_MongoDB_Driver_GridFS_OpenDownloadStreamAsync_1." >}}) is actually a [`GridFSDownloadStream`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSDownloadStream" >}}) (a subclass of [`Stream`]({{< msdnref "system.io.stream" >}})), which has the following additional members in addition to those found in [`Stream`]({{< msdnref "system.io.stream" >}}):
6062

61-
```
63+
```csharp
6264
public abstract class GridFSDownloadStream : Stream
6365
{
6466
public abstract GridFSFileInfo FileInfo { get; }
6567
public abstract Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken));
6668
};
6769
```
6870

69-
The FileInfo property contains information about the GridFS file being dowloaded. See the FindAsync method for details about the GridFSFileInfo class.
71+
The [`FileInfo`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSDownloadStream_FileInfo" >}}) property contains information about the GridFS file being dowloaded. See the [`FindAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_FindAsync" >}}) method for details about the [`GridFSFileInfo`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSFileInfo" >}}) class.
7072

71-
Calling CloseAsync is optional, but recommended. Since Stream is IDisposable and it is used inside a using statement, it would be closed automatically when Dispose is called. However, in async programming we want to avoid blocking and calling CloseAsync first allows the Stream to be closed with an async call. If you call CloseAsync first then Dispose will no longer block.
73+
{{% note %}}Calling [`CloseAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSDownloadStream_CloseAsync." >}}) is optional, but recommended. Since [`Stream`]({{< msdnref "system.io.stream" >}}) is [`IDisposable`]({{< msdnref "system.idisposable" >}}) and it is used inside a using statement, it would be closed automatically when [`Dispose`]({{< msdnref "system.idisposable.dispose" >}}) is called. However, in async programming we want to avoid blocking and calling [`CloseAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSDownloadStream_CloseAsync." >}}) first allows the [`Stream`]({{< msdnref "system.io.stream" >}}) to be closed with an async call. If you call [`CloseAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSDownloadStream_CloseAsync." >}}) first then [`Dispose`]({{< msdnref "system.idisposable.dispose" >}}) will no longer block.{{% /note %}}
7274

73-
By default the driver assumes that you want to read the entire contents of the file from beginning to end, and returns a Stream implementation that does not support seeking, which allows for a more efficient implementation.
75+
By default the driver assumes that you want to read the entire contents of the file from beginning to end, and returns a [`Stream`]({{< msdnref "system.io.stream" >}}) implementation that does not support seeking, which allows for a more efficient implementation.
7476

75-
If you do want to use Seek with the returned Stream, you can use the options parameter to indicate that.
77+
If you do want to use [`Seek`]({{< msdnref "system.io.stream.seek" >}}) with the returned [`Stream`]({{< msdnref "system.io.stream" >}}), you can use the options parameter to indicate that.
7678

77-
```
79+
```csharp
7880
IGridFSBucket bucket;
7981
ObjectId id;
8082

@@ -107,7 +109,7 @@ The default value for the revision is -1 (i.e. the newest revision).
107109

108110
The following examples all download the newest revision:
109111

110-
```
112+
```csharp
111113
IGridFSBucket bucket;
112114
string filename;
113115

@@ -129,7 +131,7 @@ using (var stream = await bucket.OpenDownloadStreamByNameAsync(filename))
129131

130132
If you want to download a different revision, you specify the desired revision using the options parameter.
131133

132-
```
134+
```csharp
133135
IGridFSBucket bucket;
134136
string filename;
135137

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
date = "2015-09-41T00:00:00Z"
2+
date = "2015-09-14T00:00:00Z"
33
draft = false
44
title = "Finding Files"
55
[menu.main]
@@ -15,11 +15,11 @@ Each file stored in GridFS has a unique Id assigned to it, and that is the prima
1515

1616
### FindAsync method
1717

18-
If you don't know the Id, you can use FindAsync to find matching files using a filter. The filter must be of type FilterDefinition&lt;GridFSFileInfo&gt;.
18+
If you don't know the Id, you can use [`FindAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_FindAsync" >}}) to find matching files using a filter. The filter must be of type [`FilterDefinition<GridFSFileInfo>`]({{< apiref "T_MongoDB_Driver_FilterDefinition_1" >}}).
1919

20-
For example, to find the newest revision of the file named "securityvideo" uploaded in January 2015 we could use FindAsync like this:
20+
For example, to find the newest revision of the file named "securityvideo" uploaded in January 2015 we could use [`FindAsync`]({{< apiref "M_MongoDB_Driver_GridFS_GridFSBucket_FindAsync" >}}) like this:
2121

22-
```
22+
```csharp
2323
IGridFSBucket bucket;
2424
var filter = Builders<GridFSFileInfo>.Filter.And(
2525
Builders<GridFSFileInfo>.Filter.EQ(x => x.Filename, "securityvideo"),
@@ -41,29 +41,8 @@ using (var cursor = await bucket.FindAsync(filter, options))
4141

4242
### GridFSFileInfo class
4343

44-
The GridFSFileInfo is a strongly typed class that represents the information about a GridFS file stored in the "fs.files" collection.
45-
46-
It is defined as:
47-
48-
```
49-
public class GridFSFileInfo
50-
{
51-
public BsonDocument BackingDocument { get; }
52-
public int ChunkSizeBytes { get; }
53-
public string Filename { get; }
54-
public ObjectId Id { get; }
55-
public long Length { get; }
56-
public string MD5 { get; }
57-
public BsonDocument Metadata { get; }
58-
public DateTime UploadDateTime { get; }
59-
60-
// the following are deprecated but kept for backward compatibility
61-
public IEnumerable<string> Aliases { get; }
62-
public string ContentType { get; }
63-
public BsonValue IdAsBsonValue { get; }
64-
}
65-
```
44+
The [`GridFSFileInfo`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSFileInfo" >}}) is a strongly typed class that represents the information about a GridFS file stored in the "fs.files" collection.
6645

67-
This class is a strongly typed wrapper around a backing BsonDocument. It makes it easier to extract the information available in a files collection documents.
46+
This class is a strongly typed wrapper around a backing [`BsonDocument`]({{< apiref "T_MongoDB_Bson_BsonDocument" >}}). It makes it easier to extract the information available in a files collection documents.
6847

69-
In older drivers it was possible to store arbitrary information at the root level of a files collection document. If you need to access that information you can use the BackingDocument property to get access to the complete backing document. When uploading new GridFS files you should store any additional information you want to associate with the uploaded file inside the Metadata document.
48+
In older drivers it was possible to store arbitrary information at the root level of a files collection document. If you need to access that information you can use the [`BackingDocument`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSFileInfo_BackingDocument" >}}) property to get access to the complete backing document. When uploading new GridFS files you should store any additional information you want to associate with the uploaded file inside the [`Metadata`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSFileInfo_Metadata" >}}) document.
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
date = "2015-09-41T00:00:00Z"
2+
date = "2015-09-14T00:00:00Z"
33
draft = false
44
title = "Getting Started"
55
[menu.main]
@@ -11,25 +11,27 @@ title = "Getting Started"
1111

1212
## Getting Started
1313

14-
GridFS files are stored in the database using two collections, normally called "fs.files" and "fs.chunks". Each file uploaded to GridFS has one document in the "fs.files" containing information about the file and as many chunks as necessary in the "fs.chunks" collection to store the contents of the file.
14+
GridFS files are stored in the database using two collections, normally called "fs.files" and "fs.chunks". Each file uploaded to GridFS has one document in the "fs.files" collection containing information about the file and as many chunks as necessary in the "fs.chunks" collection to store the contents of the file.
1515

1616
A GridFS "bucket" is the combination of an "fs.files" and "fs.chunks" collection which together represent a bucket where GridFS files can be stored.
1717

1818
### GridFSBucket
1919

20-
A GridFSBucket object is the root object representing a GridFS bucket. You should always use a GridFSBucket object to interact with GridFS instead of directly referencing the underlying collections.
20+
A [`GridFSBucket`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSBucket" >}}) object is the root object representing a GridFS bucket.
2121

22-
You create a GridFSBucket instance by calling its constructor:
22+
{{% note class="warning" %}}You should always use a [`GridFSBucket`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSBucket" >}}) object to interact with GridFS instead of directly referencing the underlying collections.{{% /note %}}
2323

24-
```
24+
You create a [`GridFSBucket`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSBucket" >}}) instance by calling its constructor:
25+
26+
```csharp
2527
IMongoDatabase database;
2628

2729
var bucket = new GridFSBucket(database);
2830
```
2931

30-
You can also provide options when instantiating the GridFSBucket object:
32+
You can also provide options when instantiating the [`GridFSBucket`]({{< apiref "T_MongoDB_Driver_GridFS_GridFSBucket" >}}) object:
3133

32-
```
34+
```csharp
3335
IMongoDatabase database;
3436

3537
var bucket = new GridFSBucket(database, new GridFSOptions
@@ -41,8 +43,8 @@ var bucket = new GridFSBucket(database, new GridFSOptions
4143
});
4244
```
4345

44-
The BucketName value is the root part of the files and chunks collection names, so in this example the two collections would be named "videos.files" and "videos.chunks" instead of "fs.files" and "fs.chunks".
46+
The [`BucketName`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSBucketOptions_BucketName" >}}) value is the root part of the files and chunks collection names, so in this example the two collections would be named "videos.files" and "videos.chunks" instead of "fs.files" and "fs.chunks".
4547

46-
The ChunkSizeBytes value defines the size of each chunk, and in this example we are overriding the default value of 261120 (255MB).
48+
The [`ChunkSizeBytes`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSBucketOptions_ChunkSizeBytes" >}}) value defines the size of each chunk, and in this example we are overriding the default value of 261120 (255MB).
4749

48-
The WriteConcern is used when uploading files to GridFS, and the ReadPreference is used when downloading files from GridFS.
50+
The [`WriteConcern`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSBucketOptions_WriteConcern" >}}) is used when uploading files to GridFS, and the [`ReadPreference`]({{< apiref "P_MongoDB_Driver_GridFS_GridFSBucketOptions_ReadPreference" >}}) is used when downloading files from GridFS.

Docs/reference/content/reference/gridfs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title = "GridFS"
1111

1212
## GridFS
1313

14-
GridFS is a way of storing binary information that is larger than the maximum document size (currently 16MB). When you upload a file to GridFS the file is broken into chunks and the individual chunks are uploaded. When you download a file from GridFS the original content is reassembled from the chunks.
14+
GridFS is a way of storing binary information larger than the maximum document size (currently 16MB). When you upload a file to GridFS the file is broken into chunks and the individual chunks are uploaded. When you download a file from GridFS the original content is reassembled from the chunks.
1515

1616
- [Getting Started]({{< relref "reference\gridfs\gettingstarted.md" >}})
1717
- [Uploading files]({{< relref "reference\gridfs\uploadingfiles.md" >}})

0 commit comments

Comments
 (0)