2

I have a compound key with field articleId_1_host_1_timeStamp_1_isIndia_1_location_1.

Cardinality of fields is

  • articleId has 20000 different value
  • host has 17 value
  • timestamp is increasing field with time

I want to use articleId_1_host_1_timeStamp_1 as shard key.

Could you please suggest if I can use this as shard key with timestamp field in it? Also do I need to create a different index using these three fields or can I use the above compound key with shard key of of first three fields?

1 Answer 1

1

You should be able to use the index listed to cover the shard key. It is a super set of your shard key fields.

The shard key listed should be fine for distributing write load, given you don't expect any individual articleId/host pairs to take the bulk of your writes at a given point in time.

I would be concerned about this shard key for reads. In order to target a single shard for a query, you need to include the shard key values. My guess is your queries do not include timestamp. Without timestamp your queries will be sent to every shard which is inefficient. With scatter gather reads, your hamper your ability to scale reads by adding shards.

3
  • i am concerned with timestamp field if i add it to shard key then will not be affecting chunk size as it is in millisecond and will keep increasing always through out the day
    – viren
    Dec 7, 2014 at 9:32
  • Is your application write or read intensive?
    – Antonios
    Dec 7, 2014 at 23:55
  • it includes both. I ave heavy writes and big aggregation operation on the data
    – viren
    Dec 8, 2014 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.