Skip to content

Commit 52a09f7

Browse files
author
Bob Grabar
committed
DOCS-656 GridFS FAQ review edits
1 parent ee4db93 commit 52a09f7

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

source/faq/developers.txt

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,43 +151,45 @@ flag to modify the file preallocation strategy.
151151

152152
.. seealso:: This wiki page that address :wiki:`MongoDB disk use <Excessive+Disk+Space>`.
153153

154-
When should and shouldn't I use GridFS?
155-
---------------------------------------
154+
.. _faq-developers-when-to-use-gridfs:
155+
156+
When should I use GridFS?
157+
-------------------------
158+
159+
For documents in a MongoDB collection, you should always use
160+
:term:`GridFS` for storing files larger than 16 MB.
161+
162+
For files on your file system, storing the files in a MongoDB database
163+
through GridFS provides advantages in a number of situations:
156164

157-
:term:`GridFS` is a specification for storing and retrieving files
158-
that exceed the :term:`BSON`-document :ref:`size limit
159-
<limit-bson-document-size>` of 16MB. You should always use GridFS
160-
for storing files larger than 16MB.
165+
- If your file system limits the number of files in a directory, you can
166+
use GridFS to store as many files as needed in a directory.
161167

162-
Additionally, GridFS storage has advantages in the following other
163-
situations as well:
168+
- When you want to store file metadata (such as description, download
169+
count, and MD5 hash) together with the file itself. GridFS stores file
170+
metadata in the same bucket as the file's content.
164171

165-
- When you have many thousands of files, GridFS tends to handle the
166-
large numbers better than many file systems.
172+
- When you want to keep your files and metadata automatically backed up.
173+
If you set up replication, MongoDB makes automatic backups of your
174+
files and metadata.
167175

168-
- When users frequently upload files. When users upload files you tend
169-
to have a lot of files, all of which are also usually replicated and
170-
backed up. GridFS lets you manage them the same way you that you
171-
manage your data. You can query the files, for example by user or
172-
upload date, directly in the file store, without a layer of
173-
indirection.
176+
- When you want to access information from random sections of large
177+
files without having to load whole files into memory. GridFS lets you
178+
access sections of files without having to read the entire file, for
179+
example skipping into the middle of a video.
174180

175-
- When files often change. If you have certain files that change a lot,
176-
consider storing them in GridFS, which then allows you to modify them
177-
in one place. Also, all clients get the updates. If you instead store
178-
in source tree, you must deploy an application to update files.
181+
Do not use GridFS if a file is under the 16 MB limit and you need to
182+
update the file atomically. Instead, consider either:
179183

180-
There are some situations where you should not use GridFS:
184+
- Storing the file manually within a single document. This can be
185+
accomplished using the BSON BinData datatype. For details on using
186+
BinData, see the :doc:`drivers </applications/drivers>` documentation
187+
for your driver.
181188

182-
- When you have only a few small and static files, such as js, css, and
183-
images on a web site.
189+
- Storing multiple versions and specifying which version is current.
190+
This can be changed atomically after the new file is uploaded.
184191

185-
.. todo Verify that this info from the wiki can be deleted:
186-
Note that if you need to update a binary object atomically, and the
187-
object is under the document size limit for your version of MongoDB
188-
(16MB for 1.8), then you might consider storing the object manually
189-
within a single document. This can be accomplished using the BSON
190-
bindata type. Check your driver's docs for details on using this type
192+
For more information on GridFS, see :doc:`/applications/gridfs`.
191193

192194
How does MongoDB address SQL or Query injection?
193195
------------------------------------------------

0 commit comments

Comments
 (0)