あなたのシャード環境以下のようなものを想像してみて--hostパラメータを経由してmongos
インスタンスに対してmongoimport
を発行する必要があります。 3つのシャードがあり、各シャードには3つのサーバーがあります。シャード環境にJSONをインポートする
今
shards:
{ "_id" : "s0", "host" : "s0/localhost:37017,localhost:37018,localhost:37019" }
{ "_id" : "s1", "host" : "s1/localhost:47018,localhost:47019" }
{ "_id" : "s2", "host" : "s2/localhost:57017,localhost:57018,localhost:57019" }
active mongoses:
"3.2.5" : 1
は、以下の手順に従ってください。
mongos経由でシャードされたインスタンスのいずれかに接続します。 mongo --port 47018、これでmongos>プロンプトが表示されます。
次のコマンドを入力します。
mongos> sh.enableSharding("sharddb");
{ "ok" : 1 }
このコマンドは、データベース "sharddbは" シャーディングのために有効であることをMongoDBの伝えます。
- ここで、断片化する必要のあるコレクションとキーを指定します。あなたはすべての詳細を指定したら
> mongos> sh.shardCollection("sharddb.neighbourhoods",{"_id":1},true)
> {"collectionsharded" : "sharddb.neighbourhoods", "ok" : 1 }
は、コマンドプロンプトから
> C:\Users\yc03ak1>mongoimport --db sharddb --collection
> "neighbourhoods" --drop --type json --host "localhost:47018" --file
> "c:\Users\yc03ak1\Desktop\neighborhoods.json"
> 2016-08-14T15:32:03.087-0700 connected to: localhost:47018
> 2016-08-14T15:32:03.091-0700 dropping: sharddb.neighbourhoods
> 2016-08-14T15:32:04.743-0700 imported 195 documents
これはsharddbなどでコレクションの地域で文書を作成しますが、以下のmongoimportコマンドを実行しますシャードされたコレクション。
あなたは
mongos> sh.status();
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("57a8f3d77ce8ef0f68a210c9")
}
shards:
{ "_id" : "s0", "host" : "s0/localhost:37017,localhost:37018,localhost:37019" }
{ "_id" : "s1", "host" : "s1/localhost:47018,localhost:47019" }
{ "_id" : "s2", "host" : "s2/localhost:57017,localhost:57018,localhost:57019" }
active mongoses:
"3.2.5" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 5
Last reported error: HostUnreachable
Time of Reported error: Thu Aug 11 2016 18:02:14 GMT-0700 (Pacific Standard Time)
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "projects", "primary" : "s1", "partitioned" : true }
projects.students
shard key: { "student_id" : 1 }
unique: false
balancing: true
chunks:
s0 1
s1 1
s2 1
{ "student_id" : { "$minKey" : 1 } } -->> { "student_id" : 1 } on : s2 Timestamp(3, 0)
{ "student_id" : 1 } -->> { "student_id" : 25 } on : s1 Timestamp(3, 1)
{ "student_id" : 25 } -->> { "student_id" : { "$maxKey" : 1 } } on : s0 Timestamp(2, 0)
{ "_id" : "test", "primary" : "s2", "partitioned" : true }
test.zipcodes
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
s2 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : s2 Timestamp(1, 0)
{ "_id" : "sharddb", "primary" : "s2", "partitioned" : true }
sharddb.neighbourhoods
shard key: { "_id" : 1 }
unique: true
balancing: true
chunks:
s2 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : s2 Timestamp(1, 0)
mongos>
によってHTH ..
をシャードコレクションをチェックすることができますしてください、あなたは私がしてくださいことを行うことができますどのように私を見ることができます。 – user2307236
私はこれを読んだので、mongoimportはmongoやmongosと接続したときに実行するつもりはないことをご了承ください – user2307236
shardedクラスタを持っていると述べたので、configインスタンスから読み込んでシャード方法を知る 'mongos'インスタンス'mongoimport'コマンドラインに' --host'と適切なIP/DNS名とポートを指定する必要があります。 – DAXaholic