@@ -22,7 +22,7 @@ Overview
22
22
23
23
In this guide, you can learn how to store and retrieve large files in
24
24
MongoDB by using **GridFS**. GridFS is a specification that describes how to split files
25
- into chunks when storing them and reassemble them when retrieving them. The {+driver-short+}'s
25
+ into chunks when storing them and reassemble those files when retrieving them. The {+driver-short+}'s
26
26
implementation of GridFS is an abstraction that manages the operations and organization of
27
27
the file storage.
28
28
@@ -58,8 +58,8 @@ When storing files with GridFS, the driver splits the files into smaller
58
58
chunks, each represented by a separate document in the ``chunks`` collection.
59
59
It also creates a document in the ``files`` collection that contains
60
60
a file ID, file name, and other file metadata. You can upload the file from
61
- memory or from a stream. See the following diagram to see how GridFS splits
62
- the files when uploaded to a bucket.
61
+ memory or from a stream. The following diagram shows how GridFS splits
62
+ the files when they're uploaded to a bucket.
63
63
64
64
.. figure:: /includes/figures/GridFS-upload.png
65
65
:alt: A diagram that shows how GridFS uploads a file to a bucket
@@ -75,16 +75,16 @@ Create a GridFS Bucket
75
75
To store or retrieve files from GridFS, create a GridFS bucket by calling the
76
76
``FSBucket.new`` method and passing in a ``Mongo::Database`` instance.
77
77
You can use the ``FSBucket`` instance to
78
- call read and write operations on the files in your bucket.
78
+ perform read and write operations on the files in your bucket.
79
79
80
80
.. literalinclude:: /includes/write/gridfs.rb
81
81
:language: ruby
82
82
:dedent:
83
83
:start-after: start-create-bucket
84
84
:end-before: end-create-bucket
85
85
86
- To create or reference a bucket with a custom name other than the default name
87
- ``fs``, pass the bucket name as the an optional parameter to the ``FSBucket.new``
86
+ To create or reference a bucket with a name other than the default name
87
+ ``fs``, pass the bucket name as an optional parameter to the ``FSBucket.new``
88
88
constructor, as shown in the following example:
89
89
90
90
.. literalinclude:: /includes/write/gridfs.rb
@@ -102,7 +102,8 @@ upload stream and saves it to the ``GridFSBucket`` instance.
102
102
You can pass a ``Hash`` as an optional parameter to configure the chunk size or include
103
103
additional metadata.
104
104
105
- The following example uploads a file into ``FSBucket``:
105
+ The following example uploads a file into ``FSBucket`` and specifies metadata for the
106
+ uploaded file:
106
107
107
108
.. literalinclude:: /includes/write/gridfs.rb
108
109
:language: ruby
@@ -119,7 +120,7 @@ about the file it refers to, including:
119
120
120
121
- The ``_id`` of the file
121
122
- The name of the file
122
- - The length/ size of the file
123
+ - The size of the file
123
124
- The upload date and time
124
125
- A ``metadata`` document in which you can store any other information
125
126
@@ -145,7 +146,7 @@ Download Files
145
146
The ``download_to_stream`` method downloads the contents of a file.
146
147
147
148
To download a file by its file ``_id``, pass the ``_id`` to the method. The ``download_to_stream``
148
- method will write the contents of the file to the provided object.
149
+ method writes the contents of the file to the provided object.
149
150
The following example downloads a file by its file ``_id``:
150
151
151
152
.. literalinclude:: /includes/write/gridfs.rb
@@ -154,9 +155,8 @@ The following example downloads a file by its file ``_id``:
154
155
:start-after: start-download-files-id
155
156
:end-before: end-download-files-id
156
157
157
- If you don't know the ``_id`` of the file but know the filename, then you
158
- can use the ``download_to_stream_by_name`` method. The following example
159
- downloads a file named ``mongodb-tutorial``:
158
+ If you a file's name but not its ``_id``, you can use the ``download_to_stream_by_name``
159
+ method. The following example downloads a file named ``mongodb-tutorial``:
160
160
161
161
.. literalinclude:: /includes/write/gridfs.rb
162
162
:language: ruby
@@ -167,7 +167,7 @@ downloads a file named ``mongodb-tutorial``:
167
167
.. note::
168
168
169
169
If there are multiple documents with the same ``filename`` value,
170
- GridFS will fetch the most recent file with the given name (as
170
+ GridFS fetches the most recent file with the given name (as
171
171
determined by the ``uploadDate`` field).
172
172
173
173
Delete Files
@@ -198,4 +198,4 @@ API Documentation
198
198
To learn more about using GridFS to store and retrieve large files,
199
199
see the following API documentation:
200
200
201
- - `Mongo::Grid::FSBucket <{+api-root+}/Mongo/Grid/FSBucket.html>`_
201
+ - `Mongo::Grid::FSBucket <{+api-root+}/Mongo/Grid/FSBucket.html>`__
0 commit comments