After building a MongoDB cluster, you need to create a database, create a table, and set the partition primary key to initialize data!
After building a MongoDB cluster, you need to create a database, create a table, and set the partition primary key to initialize data!
After building the MongoDB cluster (SEE), you need to create a database, create a table, and set the partition primary key to initialize the data!
(1) create a WLB database and set the table shards 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 cmd.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// If the wlb database does not exist, a new database is created.
Switched to db wlb
> Db. createCollection ('wlb _ orders ')// Create a table wlb_orders
{"OK": 1}
> Use admin
Switched to db admin
> Db. runCommand ({enablesharding: 'wlb '})// You Can shard the database.
{"OK": 1}
> Db. runCommand ({shardcollection: 'wlb. wlb_orders ', key: {order_id: 1 }})// Set the partition primary key of the table to order_id
{"Collectionsharded": "wlb. wlb_orders", "OK": 1}
> Db. printShardingStatus ()// Query database shard Information
--- 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}
>