Can a shard key index be the prefix of an existing index

27 views
Skip to first unread message

Kirk Dawson

unread,
Apr 27, 2017, 12:18:17 PM4/27/17
to mongodb-user
I am looking at moving an existing collection to a sharded collection.

The existing collection has a compound index on last_name first_name county etc

I am looking at using a shard key of last_name first_name. Can it use the prefix of the current index for the shard key index or do I have to create a separate one?

compchap.nikhil

unread,
Apr 27, 2017, 3:05:21 PM4/27/17
to mongodb-user
Hello Kirk,

Using "last_name first_name" as Shard key is totally valid. Since the collection already have data and index, and your shard key will be the prefix of that index so you are good to use the same index. But before you proceed with using this as your shard key you may want to consider below -
  1. Cardinality
  2. Frequency
  3. Growth trend
You may also find below link helpful.

Thanks,
Nikhil
Reply all
Reply to author
Forward
0 new messages