I have a mongos with 2 shard servers (and 3 config servers)
sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("55ae2ddab9e8641e489ce39b")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.212.182:27018" }
{ "_id" : "shard0001", "host" : "192.168.212.106:27018" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "Vision_1282", "partitioned" : true, "primary" : "shard0001" }
Vision_1282.Group
shard key: { "groepNr" : 1, "valId" : 1 }
chunks:
shard0001 1
{ "groepNr" : { "$minKey" : 1 }, "valId" : { "$minKey" : 1 } } -->> { "groepNr" : { "$maxKey" : 1 }, "valId" : { "$maxKey" : 1 } } on : shard0001 Timestamp(1, 0)
{ "_id" : "db", "partitioned" : false, "primary" : "shard0000" }
I made the shard key as follows:
db.runCommand({ shardcollection : "Vision_1282.Group", key : {groepNr : 1, valId : 1}})
I insert about 10.000 records, where the groepNr is 1, 2, 3 or 4 and a valId can be between 1 and 4001.
When I look at the shardDistribution I see that shard001 only has records where groepNr = 1 and valId = 1. All other records are in shard002.
I thought that the value behind the key value (here groepNr and valId) is 1 for ascending and -1 for descending.
PS. in PHP code, where I do the inserts I also ensure to use the index.
$collection->ensureIndex(array("groepNr" => 1 , "valId" => 1));
Did I do something wrong with creating the shardkey?
Best Answer
I have lowered the chunksize to 1 MB:
I inserted now about 10.000 documents.
If I look at the sh.status(), I see this:
Also I run the scripts AllChunkInfo("Vision_1282.Group"), with this result:
So you are right, the records were to small and the chunksize was to big.
Tx.