MongoDB cluster JavaAPI inserts data

Source: Internet
Author: User
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}

>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.