sharding 되어 있지 않은(shard key 설정이 안된) 데이타가 들어 있는 collection에 shard key 를 설정 하려고 했다.

 

명령어 :  sh.shardCollection("데이타베이스.컬렉션명",{_id:"hashed"});

결과 :

{
"ok" : 0,
"errmsg" : "Please create an index that starts with the proposed shard key before sharding the collection",
"code" : 72,
"codeName" : "InvalidOptions",
"operationTime" : Timestamp(1557813436, 4),
"$clusterTime" : {
"clusterTime" : Timestamp(1557813436, 4),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}

 

그래서 index 2개를 생성 하였다.

db.컬렉션명.createIndex({_id:1});
db.컬렉션명.createIndex({_id:"hashed"});

 

그리고 실행 

sh.shardCollection("데이타베이스.컬렉션명",{_id:"hashed"});

하니 잘되네~시간이 좀 걸리지만 점점 데이타가 맞춰진다.

 

Posted by 복태아빠
,