2016-04-30 41 views
1

對我有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應該是字符串,當前條件第一塊保存所有新數據(字符串 - > ObjectId()),第二塊只保存帶有thread_id「ObjectId()」的文檔

我試過這個命令:

reference

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

它看來, 「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 } });