@@ -537,27 +537,31 @@ returned document does not include the ``isdbgrid`` string.
537
537
Shard GridFS Documents
538
538
----------------------
539
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:
540
+ A common way to shard :term:`GridFS` is to configure the shard as follows:
542
541
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.
542
+ - Do not shard the ``files`` collection, as the keys in this collection do
543
+ not easily lend themselves to even distributions.
546
544
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 .
545
+ Leaving ``files`` unsharded means that all the file metadata documents
546
+ live on one shard. It is recommended that the shard is a replica set
547
+ with at least three members, for high availability .
550
548
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.
549
+ - Shard the ``chunks`` collection using a new ``files_id : 1 , n : 1``
550
+ index. You must create this index. Do not use the existing
551
+ ``files_id : 1 , n : 1`` index already created by the drivers.
553
552
554
- To shard "chunks" by "files_id", issue commands similar to the following:
553
+ The new ``files_id : 1 , n : 1`` index ensures that all chunks of a
554
+ given file live on the same shard, which is safer and allows FileMD5
555
+ hashing.
556
+
557
+ To shard the ``chunks`` collection by ``files_id : 1 , n : 1``, issue
558
+ commands similar to the following:
555
559
556
560
.. code-block:: javascript
557
561
558
- db.fs.chunks.ensureIndex( { files_id : 1 } )
562
+ db.fs.chunks.ensureIndex( { files_id : 1 , n : 1 } )
559
563
560
- db.runCommand( { shardcollection : "test.fs.chunks" , key : { files_id : 1 } } )
564
+ db.runCommand( { shardcollection : "test.fs.chunks" , key : { files_id : 1 , n : 1 } } )
561
565
562
566
The default ``files_id`` is an :term:`ObjectId`. The ``files_id`` is
563
567
ascending, and all GridFS chunks are sent to a single sharding chunk.
0 commit comments