@@ -534,6 +534,37 @@ a document with a ``msg`` field that holds the string
534
534
If the application is instead connected to a :program:`mongod`, the
535
535
returned document does not include the ``isdbgrid`` string.
536
536
537
+ Shard GridFS Documents
538
+ ----------------------
539
+
540
+ One common way to shard :term:`GridFS` is to do so based on pre-existing
541
+ indexes and to configure the shard as follows:
542
+
543
+ - Do not shard the "files" collection. This means all the file-metadata
544
+ documents live on one shard. It is highly recommended that the shard
545
+ is a replica set with at least three members, for resiliency.
546
+
547
+ - Shard the "chunks" collection using the index "files_id: 1". You must
548
+ create this separate index. Do not use the existing "files_id, n"
549
+ index created by the drivers.
550
+
551
+ The new "files_id" index ensures that all chunks of a given file live
552
+ on the same shard, which is safer and allows FileMD5 hashing.
553
+
554
+ To shard "chunks" by "files_id", issue commands similar to the following:
555
+
556
+ .. code-block:: javascript
557
+
558
+ db.fs.chunks.ensureIndex( { files_id : 1 } )
559
+
560
+ db.runCommand( { shardcollection : "test.fs.chunks" , key : { files_id : 1 } } )
561
+
562
+ The default ``files_id`` is an :term:`ObjectId`. The ``files_id`` is
563
+ ascending, and all GridFS chunks are sent to a single sharding chunk.
564
+ If your write load is too high for a single server to handle, you may
565
+ want to shard on a different key or use a different value for ``_id``
566
+ in the ``files`` collection.
567
+
537
568
.. index:: config database
538
569
.. index:: database, config
539
570
.. _sharding-internals-config-database:
0 commit comments