I’m getting a failure when trying to shard a large collection.
I’ve created a hashed index to shard from:
db.records.createIndex({url: "hashed"}, {background: true})
// wait a day or so
sh.shardCollection("dbName.records", {url: "hashed"})
Which returns json:
{
"ok" : 0.0,
"errmsg" : "couldn't find valid index for shard key",
"code" : 96,
"codeName" : "OperationFailed",
"operationTime" : Timestamp(1586536087, 10612),
"$clusterTime" : {
"clusterTime" : Timestamp(1586536087, 10735),
"signature" : {
"hash" : { "$binary" : "tT7Hx3/Zza2xyAPc2x3n08YrKLU=", "$type" : "00" },
"keyId" : NumberLong(6798667079034601645)
}
}
}
The only caveat I can think of is that there is a second index in existence, which covers the same field:
{url: 1}
Is this a known issue? Is there any other reason sharding would fail when the index is already in existence?
I ran into this same issue on a development environment, but recreating the index a few times eventually solved it.