Mongo single device shard-2

Source: Internet
Author: User
Mongo single device shard -- 22.16dbpleasecreateanindexovertheshardingkeybeforesharding uses a single index. If no index is found in the collection, the error config {_ id: shard1, members: [{_ id: 0, host: 127.0.0.1: 27018 },{ _ id: 1, host: 127.0.0.1: 27019 },{ _ id: 2,

Mongo single device shard -- 2 mongodb please create an index over the sharding key before sharding uses a single index. If there is no index in the collection, the error config = {_ id: shard1, members: [{_ id: 0, host: 127.0.0.1: 27018}, {_ id: 1, host: 127.0.0.1: 27019}, {_ id: 2,

Mongo single device shard-2

Mongodb please create an index over the sharding key before sharding

If a single index is used, an error is returned if no index is found in the collection.

Config = {_ id: 'shard1 ', members: [{_ id: 0, host: '192. 0.0.1: 100'}, {_ id: 1,
Host: '2017. 0.0.1: 27019 '}, {_ id: 2, host: '2017. 0.0.1: 27020 '}, {_ id: 3, host: '100. 0.0.1: 27021 '}]}

Rs. initiate (config );

Rs. add ({"_ id": 4, host: "127.0.0.1: 27022", arbiterOnly: true });

Config = {_ id: 'shard2 ', members: [{_ id: 0, host: '192. 0.0.1: 100'}, {_ id: 1,
Host: '2017. 0.0.1: 27029 '}, {_ id: 2, host: '2017. 0.0.1: 27030 '}, {_ id: 3, host: '100. 0.0.1: 27031 '}]}

Rs. initiate (config );

Rs. add ({"_ id": 4, host: "127.0.0.1: 27032", arbiterOnly: true });

Config = {_ id: 'shard3 ', members: [{_ id: 0, host: '2017. 0.0.1: 100'}, {_ id: 1,
Host: '2017. 0.0.1: 27039 '}, {_ id: 2, host: '2017. 0.0.1: 27040 '}, {_ id: 3, host: '100. 0.0.1: 27041 '}]}

Rs. initiate (config );

Rs. add ({"_ id": 4, host: "127.0.0.1: 27042", arbiterOnly: true });

Sudo mongod -- configsvr -- dbpath/data/mongo/ReplicaSetData-shard1/
Config -- port 20000 -- logpath/data/mongo/ReplicaSetData-shard1/config. log -- logappend -- fork

Sudo mongod -- configsvr -- dbpath/data/mongo/ReplicaSetData-shard2/
Config -- port 20001 -- logpath/data/mongo/ReplicaSetData-shard2/config. log -- logappend -- fork

Sudo mongod -- configsvr -- dbpath/data/mongo/ReplicaSetData-shard3/
Config -- port 20002 -- logpath/data/mongo/ReplicaSetData-shard3/config. log -- logappend -- fork

Sudo mongos -- configdb 127.0.0.1: 20000,127.0 .0.1: 20001,127.0 .0.1:
20002 -- port 30000 -- chunkSize 5 -- logpath/data/mongo/ReplicaSetData-
Shard-log/mongos. log -- logappend -- fork

Db. runCommand ({addshard: "shard1/127.0.0.1: 27018,127.0 .0.1: 27019,
Wagner. 0.0.1: 27020,127.0. 0.1:
27021,127.0 .0.1: 27022 ", name:" s1 ", maxsize: 20480 });

Db. runCommand ({addshard: "shard2/127.0.0.1: 27028,127.0 .0.1: 27029,
127.0.0.1: 27030,127.0 .0.1: 27031,
127.0.0.1: 27032 ", name:" s2 ", maxsize: 20480 });

Db. runCommand ({addshard: "shard3/127.0.0.1: 27038,127.0 .0.1: 27039,
127.0.0.1: 27040,127.0 .0.1: 27041,
127.0.0.1: 27042 ", name:" s3 ", maxsize: 20480 });

Db. runCommand ({listshards: 1 })

Db. runCommand ({enablesharding: "cooler "});

Db. runCommand ({shardcollection: "cooler. c1", key: {id: 1 }})

For (var I = 1; I <= 200003; I ++) db. c1.save ({id: I, value1: "1234567890 ",
Value2: "1234567890", value3:
"1234567890", value4: "1234567890 "});

Db. printShardingStatus ()

Db. c1.stats ()

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.