2014-10-08 24 views
0

我有一個集合,我設置分片。 我添加分片鍵時出錯!問題當我設置分片鍵

mongos> sh.shardCollection('IBSng.connection_log', {login_time:1}) 

但我表現出這樣的錯誤: 即使我設置複合碎片與login_time logout_time場,但表現出來的對我來說結果這個錯誤。

{ 
    "proposedKey" : { 
     "login_time" : 1 
    }, 
    "curIndexes" : [ 
     { 
      "v" : 1, 
      "key" : { 
       "_id" : 1 
      }, 
      "name" : "_id_", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "user_id" : 1 
      }, 
      "name" : "user_id_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "ras_id" : 1 
      }, 
      "name" : "ras_id_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "retry_count" : 1 
      }, 
      "name" : "retry_count_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "credit_used" : 1 
      }, 
      "name" : "credit_used_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "details.mac" : 1 
      }, 
      "name" : "details.mac_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "username" : 1 
      }, 
      "name" : "username_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "type_details.in_bytes" : 1, 
       "type_details.out_bytes" : 1 
      }, 
      "name" : "type_details.in_bytes_1_type_details.out_bytes_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "details.kill_reason" : 1 
      }, 
      "name" : "details.kill_reason_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "details.terminate_cause" : 1 
      }, 
      "name" : "details.terminate_cause_1", 
      "ns" : "IBSng.connection_log" 
     }, 
     { 
      "v" : 1, 
      "key" : { 
       "login_time" : -1, 
       "logout_time" : -1 
      }, 
      "name" : "login_time_-1_logout_time_-1", 
      "ns" : "IBSng.connection_log", 
      "sparse" : false 
     } 
    ], 
    "ok" : 0, 
    "errmsg" : "please create an index that starts with the shard key before sharding." 
} 

我在等你的答案。

回答

0

{login_time:1}添加索引,這與您所做的複合索引不同。

+0

謝謝,但我可以設置降序索引而不是升序索引? – user255327 2014-10-08 09:14:05

+0

@ user255327,當然可以。只要保持一致。 – Wizard 2014-10-08 09:15:35