Hello guys, I had shard database
trade , and collections order, sub_order, order_receiver_district_list.
first I mad mongodb shard cluster, runcommand
1) sh.enableSharding("trade")
2) sh.shardCollection( "trade.order", { tid: "hashed" } )
3)sh.shardCollection( "trade.order", { tid: "hashed" } )
Recently,I found order_receiver_district_list collection is datasize grow strong, so I runCommand shardCollection with mongoShell;
Im sure index exist in collection and print log;
mongos> db.order_receiver_district_list.getIndexes();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"key" : {
"ayReceiverDistrictNumber" : 1
},
"name" : "idx_ayReceiverDistrictNumber",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"key" : {
"ayStatus" : 1
},
"name" : "idx_ayStatus",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"key" : {
"sellerId" : 1
},
"name" : "idx_sellerId",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"key" : {
"sellerId" : 1,
"tid" : 1,
"storeId" : 1
},
"name" : "idx_seller_id_tid_store_id",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"unique" : true,
"key" : {
"tid" : 1,
"storeId" : 1,
"ayReceiverDistrictNumber" : 1
},
"name" : "idx_tid_storeId_ayReceiverDistrictNumber",
"ns" : "trade.order_receiver_district_list"
},
{
"v" : 2,
"key" : {
"tid" : "hashed"
},
"name" : "tid_hashed",
"ns" : "trade.order_receiver_district_list"
}
]
but response failed;
sh.shardCollection("trade.order_receiver_district_list", {tid: "hashed"})
{
"ok" : 0,
"errmsg" : "couldn't find valid index for shard key",
"code" : 96,
"codeName" : "OperationFailed",
"operationTime" : Timestamp(1582178883, 97),
"$clusterTime" : {
"clusterTime" : Timestamp(1582178883, 97),
"signature" : {
"hash" : BinData(0,"+GLqa0nYxEX4+ospdj1siAuV+YA="),
"keyId" : NumberLong("6793149755456225311")
}
}
}
please help me , why doses it the cause of the tip?