Skip to content

Instantly share code, notes, and snippets.

@RedBeard0531
Last active December 23, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedBeard0531/6611584 to your computer and use it in GitHub Desktop.
Save RedBeard0531/6611584 to your computer and use it in GitHub Desktop.
// Example Query
db.runCommand({aggregate:'zips',
explain:true,
pipeline: [
{$group: {_id:'$state', totalPop: {$sum:'$pop'}}},
{$sort: {totalPop:1}},
{$limit:10}]})
// Unsharded:
{
"stages" : [
{
"$cursor" : {
"query" : {
},
"fields" : {
"pop" : 1,
"state" : 1,
"_id" : 0
},
"coveredIndex" : false,
"cursorType" : "BasicCursor"
}
},
{
"$group" : {
"_id" : "$state",
"totalPop" : {
"$sum" : "$pop"
}
}
},
{
"$sort" : {
"sortKey" : {
"totalPop" : 1
},
"limit" : NumberLong(10)
}
}
],
"ok" : 1
}
// Sharded:
{
"splitPipeline" : {
"shardsPart" : [
{
"$group" : {
"_id" : "$state",
"totalPop" : {
"$sum" : "$pop"
}
}
}
],
"mergerPart" : [
{
"$group" : {
"_id" : "$$ROOT._id",
"totalPop" : {
"$sum" : "$$ROOT.totalPop"
},
"$doingMerge" : true
}
},
{
"$sort" : {
"sortKey" : {
"totalPop" : 1
},
"limit" : NumberLong(10)
}
}
]
},
"shards" : {
"shard0000" : {
"host" : "localhost:30001",
"stages" : [
{
"$cursor" : {
"query" : {
},
"fields" : {
"pop" : 1,
"state" : 1,
"_id" : 0
},
"coveredIndex" : false,
"cursorType" : "BasicCursor"
}
},
{
"$group" : {
"_id" : "$state",
"totalPop" : {
"$sum" : "$pop"
}
}
}
]
},
"shard0001" : {
"host" : "localhost:30002",
"stages" : [
{
"$cursor" : {
"query" : {
},
"fields" : {
"pop" : 1,
"state" : 1,
"_id" : 0
},
"coveredIndex" : false,
"cursorType" : "BasicCursor"
}
},
{
"$group" : {
"_id" : "$state",
"totalPop" : {
"$sum" : "$pop"
}
}
}
]
},
"shard0002" : {
"host" : "localhost:30003",
"stages" : [
{
"$cursor" : {
"query" : {
},
"fields" : {
"pop" : 1,
"state" : 1,
"_id" : 0
},
"coveredIndex" : false,
"cursorType" : "BasicCursor"
}
},
{
"$group" : {
"_id" : "$state",
"totalPop" : {
"$sum" : "$pop"
}
}
}
]
}
},
"ok" : 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment