Skip to content

Commit 25c8cc2

Browse files
author
Sam Kleinman
committed
DOCS-599 change shard key page faq entry
1 parent fb68f8c commit 25c8cc2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

source/administration/sharding.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ use the following procedure as a quick starting point:
146146
:term:`primary shard` for that database, where MongoDB stores all data
147147
before sharding begins.
148148

149+
.. _sharding-administration-shard-collection:
150+
149151
#. Enable sharding on a per-collection basis.
150152

151153
Finally, you must explicitly specify collections to shard. The

source/faq/sharding.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ How does sharding work with replication?
3636
To use replication with sharding, deploy each :term:`shard` as a
3737
:term:`replica set`.
3838

39+
Can I change the shard key after sharding a collection?
40+
-------------------------------------------------------
41+
42+
No.
43+
44+
There is no automatic support in MongoDB for changing a shard key
45+
after :ref:`sharding a collection
46+
<sharding-administration-shard-collection>`. This reality underscores
47+
the important of choosing a good :ref:`shard key <shard-key>`. If you
48+
*must* change a shard key after sharding a collection, the best option
49+
is to:
50+
51+
- dump all data from MongoDB into an external format.
52+
53+
- drop the original sharded collection.
54+
55+
- configure sharding using a more ideal shard key.
56+
57+
- :ref:`pre-split <sharding-administration-pre-splitting>` the shard
58+
key range to ensure initial even distribution.
59+
60+
- restore the dumped data into MongoDB.
61+
62+
See :dbcommand:`shardCollection`, :method:`sh.shardCollection()`,
63+
:doc:`/administration/sharding`, :ref:`sharding-internals-shard-key`
64+
:doc:`/tutorial/deploy-shard-cluster`, and :issue:`SERVER-4000` for
65+
more information.
66+
3967
What happens to unsharded collections in sharded databases?
4068
-----------------------------------------------------------
4169

0 commit comments

Comments
 (0)