houbin 发表于 2018-10-24 10:52:56

大数据 MongoDB 3.2.1 分片

mongos> use test  switched to db test
  mongos> for(var i=1;i sh.status()
  .......
  databases:
  {"_id" : "test","primary" : "shard0000","partitioned" : false }
  #partitioned 值为false 表示数据库尚未分片。
  mongos> sh.enableSharding("test")   #启用数据库分片
  mongos> db.users.createIndex({"id":1})   #创建索引
  mongos> sh.shardCollection("test.users",{"id":1})#表分片
  { "collectionsharded" : "test.users", "ok" : 1 }
  mongos> sh.status()
  ......
  { "id" : { "$minKey" : 1 } } -->> { "id" : 2341 } on : shard0001 Timestamp(5, 1)
  { "id" : 2341 } -->> { "id" : 4682 } on : shard0001 Timestamp(3, 0)
  { "id" : 4682 } -->> { "id" : 7023 } on : shard0000 Timestamp(6, 1)
  { "id" : 7023 } -->> { "id" : 9364 } on : shard0000 Timestamp(1, 3)
  { "id" : 9364 } -->> { "id" : 13407 } on : shard0000 Timestamp(3, 2)
  { "id" : 13407 } -->> { "id" : 21295 } on : shard0000 Timestamp(3, 3)
  { "id" : 21295 } -->> { "id" : 25976 } on : shard0001 Timestamp(4, 2)
  { "id" : 25976 } -->> { "id" : 33545 } on : shard0001 Timestamp(4, 3)
  { "id" : 33545 } -->> { "id" : 38226 } on : shard0000 Timestamp(5, 2)
  { "id" : 38226 } -->> { "id" : 45910 } on : shard0000 Timestamp(5, 3)
  { "id" : 45910 } -->> { "id" : { "$maxKey" : 1 } } on : shard0001 Timestamp(6, 0)
  #数据存放在两个分片服务器上即:shard0000、shard0001中。

页: [1]
查看完整版本: 大数据 MongoDB 3.2.1 分片