Database Reference
In-Depth Information
]
}
}
]
},
"n" : 1,
"nscanned" : 1,
"millisTotal" : 0,
"numQueries" : 1,
"numShards" : 1
}
The explain plan clearly shows that the query hit one shard, shard B, to return a single
document. 11 The query planner is also sophisticated enough to use any prefix subset
of the shard key for routing queries. This means you can also query by username
alone:
> db.spreadsheets.find({username: "Abbott"}).explain()
{
"shards" : {
"shard-b/arete:30100,arete:30101" : [
{
"cursor" : "BtreeCursor username_1__id_1",
"nscanned" : 801,
"n" : 801,
}
]
},
"n" : 801,
"nscanned" : 801,
"numShards" : 1
}
This query returns all 801 user documents but still goes to just one shard.
But what about global queries? These too are easily explain ed. Here's an example
of a query by the filename field, which is neither an index nor part of the shard key:
> db.spreadsheets.find({filename: "sheet-1"}).explain()
{
"shards" : {
"shard-a/arete:30000,arete:30002,arete:30001" : [
{
"cursor" : "BasicCursor",
"nscanned" : 102446,
"n" : 117,
"millis" : 85,
}
],
"shard-b/arete:30100,arete:30101" : [
{
"cursor" : "BasicCursor",
"nscanned" : 77754,
11
Note that in this and in the explain plans that follow, I've omitted several fields for the sake of brevity.
Search WWH ::




Custom Search