Collection Shard key with multiple fields with one field as ObjectID

124 views
Skip to first unread message

Soorya Prakash

unread,
Oct 28, 2016, 3:33:21 AM10/28/16
to mongodb-user
Hi, 
  I am sharding the collection, where I am sharding with the multiple fields in which one of the field is the ObjectId. In this case, I am not able to make hash on the ObjectId field with multiple fields.If so , will there be a any problem like all chunks go to same shards as one of the field in ObjectId. Can anyone give suggestion for this?

PhaoThu

unread,
Nov 1, 2016, 4:50:23 AM11/1/16
to mongodb-user
Why you need ObjectId on key shard , just pick a fields with less the same values and then hash it 

Soorya Prakash

unread,
Nov 1, 2016, 11:34:20 AM11/1/16
to mongod...@googlegroups.com

I needed this key as objectId as I am using it as foreign key.will it be any problem.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/kITVf_iOXmM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/da597309-564f-417b-b103-2e86f30ec392%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Adistambha

unread,
Nov 7, 2016, 12:43:29 AM11/7/16
to mongodb-user

Hi Soorya,

I am sharding the collection, where I am sharding with the multiple fields in which one of the field is the ObjectId. In this case, I am not able to make hash on the ObjectId field with multiple fields

The ObjectId is an automatically generated unique ID that is generally monotonically increasing. Using the ObjectId by itself as a shard key will result in a “hot shard”, i.e. there will be a single shard that will receive all the inserts all the time. However, if you absolutely must use a monotonically increasing field in a shard key, creating a compound shard key is recommended to avoid a hot shard.

will there be a any problem like all chunks go to same shards as one of the field in ObjectId

If the shard key is a compound key, there should be reasonably minimal impact on having a monotonically increasing field as one part of the key. Of course, it may also depends on your schema design and the rest of the fields in the shard key (e.g. other monotonically increasing field, the overall cardinality of the key, etc). The best method to find out is to perform a stress test on your shard key using your expected workload, and see if you can scale effectively if you add more shards. If you find that cannot scale beyond a certain limit during testing, it's a good indication that the shard key is not a good fit.

For more information regarding shard key selection, please see:

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages