Database Reference
In-Depth Information
Shard A
(replica set)
Shard B
(replica set)
2. Then shard B.
Queries a single shard.
1. First query shard A.
mongos router
mongos router
find({username: “Abbott”})
find({filename: “sheet-1”})
Application
server
Application
server
Figure 9.3 Targeted and global
queries against a shard cluster
Query selector includes
the shard key (targeted).
Query selector lacks
the shard key (global).
The explain command will show the exact query path taken by any given query
against a sharded cluster. Let's start with a targeted query. Here you query for a docu-
ment located in the first chunk, order-wise, of your collection.
> selector = {username: "Abbott",
"_id" : ObjectId("4e8a1372238d3bece8000012")}
> db.spreadsheets.find(selector).explain()
{
"shards" : {
"shard-b/arete:30100,arete:30101" : [
{
"cursor" : "BtreeCursor username_1__id_1",
"nscanned" : 1,
"n" : 1,
"millis" : 0,
"indexBounds" : {
"username" : [
[
"Abbott",
"Abbott"
]
],
"_id" : [
[
ObjectId("4d6d57f61d41c851ee000092"),
ObjectId("4d6d57f61d41c851ee000092")
]
 
Search WWH ::




Custom Search