无法对 mongodb 中已填充的集合进行分片
Unable to shard an already populated collection in mongodb
I 运行 使用此命令对集合进行分片的命令
sh.shardCollection("db.collection_name",{"_id":"hashed"})
我收到以下错误
{
"ok" : 0.0,
"errmsg" : "Please create an index that starts with the proposed shard key before sharding the collection",
"code" : 72,
"codeName" : "InvalidOptions",
"operationTime" : Timestamp(1582011118, 65),
"$clusterTime" : {
"clusterTime" : Timestamp(1582011118, 65),
"signature" : {
"hash" : { "$binary" : "jOIjTJkZKkC2ZI5lFQwX4Q7QNfs=", "$type" : "00" },
"keyId" : NumberLong(6774859010160984065)
}
}
}
_id
上已有索引
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "db.collection_name"
}
我是运行Mongo4.0.0分片集群设置
如果您正在对已经填充的集合进行分片。那你应该试试 :
我有数据库测试和集合名称作为人。基本上你需要创建一个索引来分片已经填充的集合。 Select 集合中的密钥并对其进行哈希处理
mongos> db.people.createIndex({ "user_id" : "hashed" }) ///
db.collection.createIndex({ "key" : "hashed"})
{
"raw" : {
"foo/localhost:27017,localhost:27018,localhost:27019" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 4,
"numIndexesAfter" : 5,
"ok" : 1
}
},
"ok" : 1,
"operationTime" : Timestamp(1593154931, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1593154931, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
mongos> sh.shardCollection("test.people", { "user_id": "hashed" })
{
"collectionsharded" : "test.people",
"collectionUUID" : UUID("4ee30d04-8dc9-43dc-94f6-a898bc96da89"),
"ok" : 1,
"operationTime" : Timestamp(1593154958, 11),
"$clusterTime" : {
"clusterTime" : Timestamp(1593154958, 11),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos> sh.isBalancerRunning()
正确
希望对您有所帮助!!
I 运行 使用此命令对集合进行分片的命令
sh.shardCollection("db.collection_name",{"_id":"hashed"})
我收到以下错误
{
"ok" : 0.0,
"errmsg" : "Please create an index that starts with the proposed shard key before sharding the collection",
"code" : 72,
"codeName" : "InvalidOptions",
"operationTime" : Timestamp(1582011118, 65),
"$clusterTime" : {
"clusterTime" : Timestamp(1582011118, 65),
"signature" : {
"hash" : { "$binary" : "jOIjTJkZKkC2ZI5lFQwX4Q7QNfs=", "$type" : "00" },
"keyId" : NumberLong(6774859010160984065)
}
}
}
_id
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "db.collection_name"
}
我是运行Mongo4.0.0分片集群设置
如果您正在对已经填充的集合进行分片。那你应该试试 :
我有数据库测试和集合名称作为人。基本上你需要创建一个索引来分片已经填充的集合。 Select 集合中的密钥并对其进行哈希处理
mongos> db.people.createIndex({ "user_id" : "hashed" }) ///
db.collection.createIndex({ "key" : "hashed"})
{
"raw" : {
"foo/localhost:27017,localhost:27018,localhost:27019" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 4,
"numIndexesAfter" : 5,
"ok" : 1
}
},
"ok" : 1,
"operationTime" : Timestamp(1593154931, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1593154931, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
mongos> sh.shardCollection("test.people", { "user_id": "hashed" })
{
"collectionsharded" : "test.people",
"collectionUUID" : UUID("4ee30d04-8dc9-43dc-94f6-a898bc96da89"),
"ok" : 1,
"operationTime" : Timestamp(1593154958, 11),
"$clusterTime" : {
"clusterTime" : Timestamp(1593154958, 11),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos> sh.isBalancerRunning()
正确
希望对您有所帮助!!