Reputation: 67
I have a mongo collection that I need to shard. I am having a hard time understanding the docs; I have thought of doing this in two ways.
My doc:
public class MyShardedDocument
{
public int DocID;
public int AnotherIDThatMatters;
}
Approach 1:
ShardKey = DocID.ToString() + AnotherIDThatMatters.ToString()
ShardKey
sh.shardCollection( "myDB.myCollection", { "ShardKey ": 1 })
Approach 2:
DocID
, AnotherIDThatMatters
sh.shardCollection( "myDB.myCollection", { "DocID": 1,"AnotherIDThatMatters": 1 })
Are both of these valid?
Upvotes: 2
Views: 305
Reputation: 9473
this solution relays on c# code execution, and if any document will be added to collection by other input than your application, shard key data will fail.
this approach is universal, relays on data in the document (no external processing) and every inserted document is covered regardless of how it was inserted.
Upvotes: 1