Skip to content

Instantly share code, notes, and snippets.

@asya999
Last active June 10, 2020 19:39
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 asya999/68bb73d0c55c2950f98e92d0daf8dbaa to your computer and use it in GitHub Desktop.
Save asya999/68bb73d0c55c2950f98e92d0daf8dbaa to your computer and use it in GitHub Desktop.
Explain aggregation 4 stages with group and slice
{
"stages" : [
{
"$cursor" : {
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "agg.scores",
"indexFilterSet" : false,
"parsedQuery" : {
"game" : {
"$in" : [
"G0",
"G100",
"G500"
]
}
},
"queryHash" : "3BADF9B3",
"planCacheKey" : "1268FF8C",
"winningPlan" : {
"stage" : "PROJECTION_COVERED",
"transformBy" : {
"game" : 1,
"player" : 1,
"score" : 1,
"_id" : 0
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"game" : 1,
"score" : -1,
"player" : 1
},
"indexName" : "game_1_score_-1_player_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"game" : [ ],
"score" : [ ],
"player" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"game" : [
"[\"G0\", \"G0\"]",
"[\"G100\", \"G100\"]",
"[\"G500\", \"G500\"]"
],
"score" : [
"[MaxKey, MinKey]"
],
"player" : [
"[MinKey, MaxKey]"
]
}
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 78051,
"executionTimeMillis" : 185,
"totalKeysExamined" : 78053,
"totalDocsExamined" : 0,
"executionStages" : {
"stage" : "PROJECTION_COVERED",
"nReturned" : 78051,
"executionTimeMillisEstimate" : 9,
"works" : 78053,
"advanced" : 78051,
"needTime" : 1,
"needYield" : 0,
"saveState" : 81,
"restoreState" : 81,
"isEOF" : 1,
"transformBy" : {
"game" : 1,
"player" : 1,
"score" : 1,
"_id" : 0
},
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 78051,
"executionTimeMillisEstimate" : 4,
"works" : 78053,
"advanced" : 78051,
"needTime" : 1,
"needYield" : 0,
"saveState" : 81,
"restoreState" : 81,
"isEOF" : 1,
"keyPattern" : {
"game" : 1,
"score" : -1,
"player" : 1
},
"indexName" : "game_1_score_-1_player_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"game" : [ ],
"score" : [ ],
"player" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"game" : [
"[\"G0\", \"G0\"]",
"[\"G100\", \"G100\"]",
"[\"G500\", \"G500\"]"
],
"score" : [
"[MaxKey, MinKey]"
],
"player" : [
"[MinKey, MaxKey]"
]
},
"keysExamined" : 78053,
"seeks" : 2,
"dupsTested" : 0,
"dupsDropped" : 0
}
}
}
},
"nReturned" : NumberLong(78051),
"executionTimeMillisEstimate" : NumberLong(100)
},
{
"$group" : {
"_id" : "$game",
"top5" : {
"$push" : {
"player" : "$player",
"score" : "$score"
}
}
},
"nReturned" : NumberLong(3),
"executionTimeMillisEstimate" : NumberLong(177)
},
{
"$set" : {
"top5" : {
"$slice" : [
"$top5",
{
"$const" : 0
},
{
"$const" : 5
}
]
}
},
"nReturned" : NumberLong(3),
"executionTimeMillisEstimate" : NumberLong(177)
},
{
"$sort" : {
"sortKey" : {
"_id" : 1
}
},
"nReturned" : NumberLong(3),
"executionTimeMillisEstimate" : NumberLong(177)
}
],
"serverInfo" : {
"host" : "asyas-mbp-4.lan",
"port" : 27017,
"version" : "4.4.0-rc7",
"gitVersion" : "b79b53f55a5c148fd297b81a45c08d08e2cf8f94"
},
"ok" : 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment