mongodb分片建片键的问题

月夜的黑猫 发布于 2016/10/21 16:41
阅读 481
收藏 0

在测试环境搭了个mongodb分片集群

两台服务器,分片状态如下:

shards:
        {  "_id" : "shard1",  "host" : "shard1/10.183.24.123:12001,10.183.24.124:12001" }
        {  "_id" : "shard2",  "host" : "shard2/10.183.24.123:12002,10.183.24.124:12002" }

文档已经创建了两个唯一索引

[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "DBM.t_instance_CABINET"
        },
        {
                "v" : 1,
                "unique" : true,
                "key" : {
                        "instanceId" : NumberLong(1)
                },
                "name" : "instanceId_1",
                "ns" : "DBM.t_instance_CABINET",
                "sparse" : false,
                "background" : true
        },
        {
                "v" : 1,
                "unique" : true,
                "key" : {
                        "name" : NumberLong(1)
                },
                "name" : "name_1",
                "ns" : "DBM.t_instance_CABINET",
                "sparse" : true,
                "background" : true
        }
]

现在要对这个collection创建片键,然后报错了

        "ok" : 0,
        "errmsg" : "can't shard collection DBM.t_instance_CABINET' with unique index on { instanceId: 1 } and proposed shard key { RACK_NUM: \"hashed\" }. Uniqueness can't be maintained unless shard key is a prefix"

请教下,是否是之前建的2个唯一索引导致现在建片键的时候报错呢?如果要建片键,应该如何处理呢?

加载中
返回顶部
顶部