Sharding-06-Working with Sharded Cluster

1. Find Documents Using Shard Key


mongos> db.mybooks.find({_id:10000})

{ "_id" : 10000, "name" : "book_number_10000", "author" : "author",
"description" : "this is a book" }

mongos> db.mybooks.find({_id:1})

{ "_id" : 1, "name" : "book_number_1", "author" : "author" } mongos> db.mybooks.find({_id:50000})

{ "_id" : 50000, "name" : "book_number_50000", "author" : "author",
"description" : "this is a book" }

2.	Find Documents Using Shard Key and Check Number Of Shards Scanned and Used


mongos> db.mybooks.find({_id:10000}).explain()

{
"clusteredType" : "ParallelSort",
"shards" : {

"ReplicaSetNew3/localhost.localdomain:27031,localhost.localdomain:27 032,localhost.localdomain:27033" : [
{
"cursor" : "IDCursor",
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"indexOnly" : false,
"millis" : 0,
"indexBounds" : {
"_id" : [
[
10000,
10000]
]
},
"server" : "localhost.localdomain:27031"

}
]
},
"cursor" : "IDCursor",
"n" : 1,
"nscanned" : 1,
"nscannedObjects" : 1,
"millisShardTotal" : 0,
"millisShardAvg" : 0,

"numQueries" : 1,
"numShards" : 1,
"indexBounds" : {
"_id" : [[
10000,
10000
]
]
},
"millis" : 15

}

3.	Find Documents Without Using Shard Key and Check Number Of Shards Scanned and Used

mongos> db.mybooks.find({name:"book_number_10000"}).explain()

{

"clusteredType" : "ParallelSort",
"shards" : {
"ReplicaSetNew1/localhost.localdomain:27011,localhost.localdomain:27 012,localhost.localdomain:27013" : [
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 9613,
"nscanned" : 9613,
"nscannedObjectsAllPlans" : 9613,
"nscannedAllPlans" : 9613,

"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 75,
"nChunkSkips" : 0,
"millis" : 18,
"server" : "localhost.localdomain:27011",
"filterSet" : false
}

],
"ReplicaSetNew2/localhost.localdomain:27021,localhost.localdomain:27 022,localhost.localdomain:27023" : [
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 0,
"nscanned" : 0,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 0,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"server" : "localhost.localdomain:27021",
"filterSet" : false
}
],

"ReplicaSetNew3/localhost.localdomain:27031,localhost.localdomain:27 032,localhost.localdomain:27033" : [
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 40388,
"nscanned" : 40388,
"nscannedObjectsAllPlans" : 40388,
"nscannedAllPlans" : 40388,

"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 315,
"nChunkSkips" : 0,
"millis" : 54,
"server" : "localhost.localdomain:27031",
"filterSet" : false
}
]
},
"cursor" : "BasicCursor",
"n" : 1,
"nChunkSkips" : 0,
"nYields" : 390,
"nscanned" : 50001,

"nscannedAllPlans" : 50001,
"nscannedObjects" : 50001,
"nscannedObjectsAllPlans" : 50001,
"millisShardTotal" : 72,
"millisShardAvg" : 24,
"numQueries" : 3,
"numShards" : 3,
"millis" : 57
}


4. Exit From Mongo Shell

mongos> exit

bye

Leave a Reply

Your email address will not be published.