我在集合" post"上有shardkey {thread_id:1,_ id:1}, 我想合并2个以下的块:
{
"_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"
}
它需要合并,因为thread_id应该是字符串,当前条件第一个块保存所有新数据(string - > ObjectId()),第二个块只保存带有thread_id的文件" ObjectId()&# 34;
我试过这个命令:
db.runCommand({
mergeChunks : 'forum.post',
bounds : [{
thread_id : "547dc7c2de2cf22b688b4572",
_id : ObjectId("549c519660e24b65118b456c")
}, {
thread_id : {
$type : 127
},
_id : {
$type : 127
}
}
]
})
我收到了这个错误:
{
"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
答案 0 :(得分:0)
看起来" 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 });
For" Query"我们应该使用:
db.foo.find({ id : { $type : 127 } });