Buscar

jueves, 4 de diciembre de 2014

MongoDB course for developers. unit 6/8. Application Engineering. Homeworks

Homework 6.1





Which of the following statements are true about MongoDB replication. Check all that apply.

Homework 6.2

Let's suppose you have a five member replica set and want to assure that writes are committed to the journal and are acknowledged by at least 3 nodes before you proceed forward. What would be the appropriate settings for w and j?

Homework 6.3

Which of the following statements are true about choosing and using a shard key:

Homework 6.4

You have a sharded system with three shards and have sharded the collections "grades" in the "test" database across those shards. The output of sh.status() when connected to mongos looks like this:
mongos> sh.status()
--- Sharding Status --- 
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
 {  "_id" : "s0",  "host" : "s0/localhost:37017,localhost:37018,localhost:37019" }
 {  "_id" : "s1",  "host" : "s1/localhost:47017,localhost:47018,localhost:47019" }
 {  "_id" : "s2",  "host" : "s2/localhost:57017,localhost:57018,localhost:57019" }
  databases:
 {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
 {  "_id" : "test",  "partitioned" : true,  "primary" : "s0" }
  test.grades chunks:
    s1 4
    s0 4
    s2 4
   { "student_id" : { $minKey : 1 } } -->> { "student_id" : 0 } on : s1 Timestamp(12000, 0) 
   { "student_id" : 0 } -->> { "student_id" : 2640 } on : s0 Timestamp(11000, 1) 
   { "student_id" : 2640 } -->> { "student_id" : 91918 } on : s1 Timestamp(10000, 1) 
   { "student_id" : 91918 } -->> { "student_id" : 176201 } on : s0 Timestamp(4000, 2) 
   { "student_id" : 176201 } -->> { "student_id" : 256639 } on : s2 Timestamp(12000, 1) 
   { "student_id" : 256639 } -->> { "student_id" : 344351 } on : s2 Timestamp(6000, 2) 
   { "student_id" : 344351 } -->> { "student_id" : 424983 } on : s0 Timestamp(7000, 2) 
   { "student_id" : 424983 } -->> { "student_id" : 509266 } on : s1 Timestamp(8000, 2) 
   { "student_id" : 509266 } -->> { "student_id" : 596849 } on : s1 Timestamp(9000, 2) 
   { "student_id" : 596849 } -->> { "student_id" : 772260 } on : s0 Timestamp(10000, 2) 
   { "student_id" : 772260 } -->> { "student_id" : 945802 } on : s2 Timestamp(11000, 2) 
   { "student_id" : 945802 } -->> { "student_id" : { $maxKey : 1 } } on : s2 Timestamp(11000, 3) 
If you ran the query
use test
db.grades.find({'student_id':530289})
Which shards would be involved in answering the query?

Homework 6.5

Create three directories for the three mongod processes. On unix, this could be done as follows:
mkdir -p /data/rs1 /data/rs2 /data/rs3
Now start three mongo instances as follows. Note that are three commands. The browser is probably wrapping them visually.
./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --fork

./mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --smallfiles --fork

./mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --smallfiles --fork
Now connect to a mongo shell and make sure it comes up
./mongo --port 27017
Now you will create the replica set. Type the following commands into the mongo shell:
config = { _id: "m101", members:[
          { _id : 0, host : "localhost:27017"},
          { _id : 1, host : "localhost:27018"},
          { _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);
At this point, the replica set should be coming up. You can type
rs.status()
to see the state of replication. 

m101:PRIMARY> rs.status()
{
"set" : "m101",
"date" : ISODate("2014-12-04T18:50:17Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 234,
"optime" : Timestamp(1417718826, 1),
"optimeDate" : ISODate("2014-12-04T18:47:06Z"),
"electionTime" : Timestamp(1417718835, 1),
"electionDate" : ISODate("2014-12-04T18:47:15Z"),
"self" : true
},
{
"_id" : 1,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 190,
"optime" : Timestamp(1417718826, 1),
"optimeDate" : ISODate("2014-12-04T18:47:06Z"),
"lastHeartbeat" : ISODate("2014-12-04T18:50:17Z"),
"lastHeartbeatRecv" : ISODate("2014-12-04T18:50:17Z"),
"pingMs" : 0,
"syncingTo" : "localhost:27017"
},
{
"_id" : 2,
"name" : "localhost:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 190,
"optime" : Timestamp(1417718826, 1),
"optimeDate" : ISODate("2014-12-04T18:47:06Z"),
"lastHeartbeat" : ISODate("2014-12-04T18:50:17Z"),
"lastHeartbeatRecv" : ISODate("2014-12-04T18:50:17Z"),
"pingMs" : 0,
"syncingTo" : "localhost:27017"
}
],
"ok" : 1
}

2 comentarios:




  1. Thank you! This was so helpful. The step by step approach you took made trying to replicate this with my variables very understandable.

    App Development Course Online

    ResponderEliminar


  2. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    MongoDB Training Centers in Chenai


    ResponderEliminar