Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分片集群上具有$maxkey值的Mongodb合并块_Mongodb - Fatal编程技术网

分片集群上具有$maxkey值的Mongodb合并块

分片集群上具有$maxkey值的Mongodb合并块,mongodb,Mongodb,我有shardkey{thread\u id:1,\u id:1}在集合“post”上, 我想合并以下两个块: { "_id" : "forum.post-thread_id_\"547dc7c2de2cf22b688b4572\"_id_ObjectId('549c519660e24b65118b456c')", "lastmod" : Timestamp(3012, 3), "lastmodEpoch" : ObjectId("50829c0e172de38a3398

我有shardkey{thread\u id:1,\u id:1}在集合“post”上, 我想合并以下两个块:

{
    "_id" : "forum.post-thread_id_\"547dc7c2de2cf22b688b4572\"_id_ObjectId('549c519660e24b65118b456c')",
    "lastmod" : Timestamp(3012, 3),
    "lastmodEpoch" : ObjectId("50829c0e172de38a3398f72c"),
    "ns" : "forum.post",
    "min" : {
        "thread_id" : "547dc7c2de2cf22b688b4572",
        "_id" : ObjectId("549c519660e24b65118b456c")
    },
    "max" : {
        "thread_id" : ObjectId("50901d4e1dd7198161000063"),
        "_id" : ObjectId("50901d4e1dd7198161000068")
    },
    "shard" : "shard3"
}
{
    "_id" : "forum.post-thread_id_ObjectId('50901d4e1dd7198161000063')_id_ObjectId('50901d4e1dd7198161000068')",
    "lastmod" : Timestamp(604, 0),
    "lastmodEpoch" : ObjectId("50829c0e172de38a3398f72c"),
    "ns" : "forum.post",
    "min" : {
        "thread_id" : ObjectId("50901d4e1dd7198161000063"),
        "_id" : ObjectId("50901d4e1dd7198161000068")
    },
    "max" : {
        "thread_id" : {
            "$maxKey" : 1
        },
        "_id" : {
            "$maxKey" : 1
        }
    },
    "shard" : "shard3"
}
它需要合并,因为线程id应该是字符串,在当前条件下,第一个块保存所有新数据(字符串->对象id()),第二个块只保存线程id为“对象id()的文档

我试过这个命令:

db.runCommand({
    mergeChunks : 'forum.post',
    bounds : [{
            thread_id : "547dc7c2de2cf22b688b4572",
            _id : ObjectId("549c519660e24b65118b456c")
        }, {
            thread_id : MaxKey,
            _id : MaxKey
        }
    ]
})

我得到了这个错误:

{
    "ok" : 0,
    "errmsg" : "shard key bounds [{
          thread_id: " 547dc7c2de2cf22b688b4572 ", 
          _id: ObjectId(" 549c519660e24b65118b456c ") 
    },{ 
          thread_id: { $type: 127 }, _id: { $type: 127 } })
          are not valid for shard key pattern { thread_id: 1.0, _id: 1.0 }"
}
有人知道如何解决这个问题吗

Mongodb版本2.4.9

看来“mergechunk”命令出现在更高版本2.6.x上++

我使用以下命令解决了问题:

db.runCommand({
    mergeChunks : 'forum.post',
    bounds : [{
            thread_id : "547dc7c2de2cf22b688b4572",
            _id : ObjectId("549c519660e24b65118b456c")
        }, {
            thread_id : MaxKey,
            _id : MaxKey
        }
    ]
})
对于“写入”,我们似乎应该使用:

db.foo.insert({id:MaxKey})

对于“查询”,我们应使用:

db.foo.find({id:{$type:127})

看来“mergechunk”命令出现在更高版本2.6.x上++

我使用以下命令解决了问题:

db.runCommand({
    mergeChunks : 'forum.post',
    bounds : [{
            thread_id : "547dc7c2de2cf22b688b4572",
            _id : ObjectId("549c519660e24b65118b456c")
        }, {
            thread_id : MaxKey,
            _id : MaxKey
        }
    ]
})
对于“写入”,我们似乎应该使用:

db.foo.insert({id:MaxKey})

对于“查询”,我们应使用:

db.foo.find({id:{$type:127})