【发布时间】:2015-10-20 16:38:42
【问题描述】:
我是 MongoDB 分片的新手。我在mongos 和config server 上创建了mongos 和xyz.com 上的一个分片,在xyzshard.com 服务器上创建了第二个分片:
mongosxyz.com:27019config serverxyz.com:27018xyz.com:27017上的第一个分片xyzshard.com:27017上的第二个分片
我的数据库是test,集合是test_collection。我在test.test_collection 上启用了分片。
我已经使用 "hash" 索引了 _id 字段
db.test_collection.ensureIndex( { _id : "hashed" } )
我运行以下命令:
for (var i = 1; i <= 500; i++)
db.test_collection.insert( { x : i } )
我得到以下输出:
WriteResult({ "nInserted" : 1 })
但是当我像这样在两个分片上运行查找查询时:
db.test_collection.find()
我得到每个分片上的所有文档。
这是正确的方式还是我哪里出错了?
xyz.com 上 sh.status() 的输出是
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("55b8d3e9a8742d49164820b6")
}
shards:
{ "_id" : "shard0000", "host" : "localhost:27017" }
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
test.test_collection
shard key: { "_id" : "hashed" }
chunks:
shard0000 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : shard0000 Timestamp(1, 1)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2)
{ "_id" : "test_db", "partitioned" : false, "primary" : "shard0000" }
{ "_id" : "db", "partitioned" : false, "primary" : "shard0000" }
xyzshard.com 上 sh.status() 的输出
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("55b8d3e9a8742d49164820b6")
}
shards:
{ "_id" : "shard0000", "host" : "localhost:27017" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
test.test_collection
shard key: { "_id" : "hashed" }
chunks:
shard0000 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : shard0000 Timestamp(1, 1)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2)
{ "_id" : "test_db", "partitioned" : false, "primary" : "shard0000" }
{ "_id" : "db", "partitioned" : false, "primary" : "shard0000" }
【问题讨论】:
-
你的意思是你得到了 500 个文档作为对 both 分片的
find查询的结果?或者总结一下,例如xyz.com200,xyzshard.com300? -
是的...我在两个分片上各获得 500 个文档
-
你可以试试 sh.status:docs.mongodb.org/manual/reference/method/sh.status
-
你得到什么输出?可以贴吗?
-
嗨,我已经在问题中添加了输出