Home > Database > Mysql Tutorial > MongoDB集群JavaAPI插入数据

MongoDB集群JavaAPI插入数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:09:11
Original
1033 people have browsed it

在完成了MongoDB集群的搭建工作之后,需要做的就是建立一个数据库,建立表,设置分片主键来初始化数据了!

在完成了MongoDB集群的搭建工作之后(见 ),需要做的就是建立一个数据库,建立表,设置分片主键来初始化数据了!

(1)建立WLB数据库,设置分表wlb_orders

 D:/mongodb-win32-i386-1.8.0/cmd>cd d:/mongodb-win32-i386-1.8.0/bin

D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:50000
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:50000/test
> use admin
switched to db admin
> printShardingStatus()
--- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      {
        "_id" : "ShardSetA",
        "host" : "setA/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002"
}
      {
        "_id" : "ShardSetB",
        "host" : "setB/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002"
}
      {
        "_id" : "ShardSetC",
        "host" : "setC/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
}
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }

> use wlb //在wlb数据库不存在的情况下,,就会新建一个数据库
switched to db wlb
> db.createCollection('wlb_orders') //创建一个表wlb_orders
{ "ok" : 1 }
> use admin
switched to db admin
> db.runCommand({enablesharding:'wlb'}) //设置数据库可以分片
{ "ok" : 1 }
> db.runCommand({shardcollection:'wlb.wlb_orders',key:{order_id:1}})  //设置表的分区主键为order_id
{ "collectionsharded" : "wlb.wlb_orders", "ok" : 1 }
> db.printShardingStatus() //查询数据库分片信息
--- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      {
        "_id" : "ShardSetA",
        "host" : "setA/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002"
}
      {
        "_id" : "ShardSetB",
        "host" : "setB/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002"
}
      {
        "_id" : "ShardSetC",
        "host" : "setC/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
}
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }
        { "_id" : "wlb", "partitioned" : true, "primary" : "ShardSetA" }
                wlb.wlb_orders chunks:
                                ShardSetA       1
                        { "order_id" : { $minKey : 1 } } -->> { "order_id" : { $maxKey : 1 } } on : ShardSetA { "t" : 1000, "i" : 0 }

>

linux

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template