Last active
December 23, 2015 08:59
-
-
Save RedBeard0531/6611584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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