-
$ mkdir -p /data/configdb -
$ mongod --configsvr --port 27010starta mongod -
$ mongos --configdb localhost:27010 --port 27011cria router -
$ mkdir /data/shard1 && mkdir /data/shard2 && mkdir /data/shard3cria pasta pros shards -
Start shards
$ mongod --port 27012 --dbpath /data/shard1 # shard1 $ mongod --port 27013 --dbpath /data/shard2 # shard2 $ mongod --port 27014 --dbpath /data/shard3 # shard3
-
$ mongo --port 27011 --host localhostconecta no router -
Adcionar shards
$ sh.addShard("localhost:27012") $ sh.addShard("localhost:27013") $ sh.addShard("localhost:27014")
-
$ sh.enableSharding("test")enable sharding na db test -
$ sh.shardCollection("test.users", {"_id" : 1})enable shard na collection user, diz que a shardkey é _id -
Colocar dados:
for (var i=0; i<100000; i++) { db.users.insert({ "username" : "user"+i, "created_at" : new Date(), "nick" : "nick"+i, "idade": Math.floor(Math.random() * 100), "bigtext": bigtext }); } db.users.count();
-
sh.status()retorna um sumário do Cluster -
db.users.find({_id: pegar_ao_vivo})-> Busca um usuário (Query Normal) -
db.users.find({_id: pegar_ao_vivo})-> Mostra que apenas um shard respondeu à consulta -
db.users.find({idade: 50}).explain()-> Mostra que foi preciso encaminhar para todos os shards
Last active
June 17, 2016 23:43
-
-
Save vieiralucas/a1661dbf80c6525ab28c2c3ebb618be5 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment