|
Here is explain plan for such an aggregation:
db.ticks.explain().aggregate({$sort:{Symbol:1, Timestamp:1}},{$group:{_id:"$Symbol", first:{$first:"$start"},last:{$last:"$start"}, sum:{$sum:"$Volume"}}})
|
{
|
"needsPrimaryShardMerger" : false,
|
"splitPipeline" : {
|
"shardsPart" : [
|
{
|
"$sort" : {
|
"sortKey" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
}
|
}
|
},
|
{
|
"$project" : {
|
"_id" : false,
|
"Volume" : true,
|
"Timestamp" : true,
|
"start" : true,
|
"Symbol" : true
|
}
|
}
|
],
|
"mergerPart" : [
|
{
|
"$sort" : {
|
"sortKey" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"mergePresorted" : true
|
}
|
},
|
{
|
"$group" : {
|
"_id" : "$Symbol",
|
"first" : {
|
"$first" : "$start"
|
},
|
"last" : {
|
"$last" : "$start"
|
},
|
"sum" : {
|
"$sum" : "$Volume"
|
}
|
}
|
}
|
]
|
},
|
"shards" : {
|
"shard0000" : {
|
"host" : "Asyas-MacBook-Pro.local:20000",
|
"stages" : [
|
{
|
"$cursor" : {
|
"query" : {
|
|
},
|
"sort" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"fields" : {
|
"Symbol" : 1,
|
"Timestamp" : 1,
|
"Volume" : 1,
|
"start" : 1,
|
"_id" : 0
|
},
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "spark.ticks",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
|
},
|
"winningPlan" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "SHARDING_FILTER",
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"indexName" : "Symbol_1_Timestamp_1",
|
"isMultiKey" : false,
|
"multiKeyPaths" : {
|
"Symbol" : [ ],
|
"Timestamp" : [ ]
|
},
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : false,
|
"indexVersion" : 2,
|
"direction" : "forward",
|
"indexBounds" : {
|
"Symbol" : [
|
"[MinKey, MaxKey]"
|
],
|
"Timestamp" : [
|
"[MinKey, MaxKey]"
|
]
|
}
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
}
|
}
|
},
|
{
|
"$project" : {
|
"_id" : false,
|
"Symbol" : true,
|
"start" : true,
|
"Timestamp" : true,
|
"Volume" : true
|
}
|
}
|
]
|
},
|
"shard0001" : {
|
"host" : "Asyas-MacBook-Pro.local:20001",
|
"stages" : [
|
{
|
"$cursor" : {
|
"query" : {
|
|
},
|
"sort" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"fields" : {
|
"Symbol" : 1,
|
"Timestamp" : 1,
|
"Volume" : 1,
|
"start" : 1,
|
"_id" : 0
|
},
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "spark.ticks",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
|
},
|
"winningPlan" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "SHARDING_FILTER",
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"indexName" : "Symbol_1_Timestamp_1",
|
"isMultiKey" : false,
|
"multiKeyPaths" : {
|
"Symbol" : [ ],
|
"Timestamp" : [ ]
|
},
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : false,
|
"indexVersion" : 2,
|
"direction" : "forward",
|
"indexBounds" : {
|
"Symbol" : [
|
"[MinKey, MaxKey]"
|
],
|
"Timestamp" : [
|
"[MinKey, MaxKey]"
|
]
|
}
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
}
|
}
|
},
|
{
|
"$project" : {
|
"_id" : false,
|
"Symbol" : true,
|
"start" : true,
|
"Timestamp" : true,
|
"Volume" : true
|
}
|
}
|
]
|
},
|
"shard0002" : {
|
"host" : "Asyas-MacBook-Pro.local:20002",
|
"stages" : [
|
{
|
"$cursor" : {
|
"query" : {
|
|
},
|
"sort" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"fields" : {
|
"Symbol" : 1,
|
"Timestamp" : 1,
|
"Volume" : 1,
|
"start" : 1,
|
"_id" : 0
|
},
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "spark.ticks",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
|
},
|
"winningPlan" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "SHARDING_FILTER",
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"Symbol" : 1,
|
"Timestamp" : 1
|
},
|
"indexName" : "Symbol_1_Timestamp_1",
|
"isMultiKey" : false,
|
"multiKeyPaths" : {
|
"Symbol" : [ ],
|
"Timestamp" : [ ]
|
},
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : false,
|
"indexVersion" : 2,
|
"direction" : "forward",
|
"indexBounds" : {
|
"Symbol" : [
|
"[MinKey, MaxKey]"
|
],
|
"Timestamp" : [
|
"[MinKey, MaxKey]"
|
]
|
}
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
}
|
}
|
},
|
{
|
"$project" : {
|
"_id" : false,
|
"Symbol" : true,
|
"start" : true,
|
"Timestamp" : true,
|
"Volume" : true
|
}
|
}
|
]
|
}
|
},
|
"ok" : 1,
|
"logicalTime" : {
|
"clusterTime" : Timestamp(1493051213, 1),
|
"signature" : {
|
"hash" : BinData(0,"A0w/++3Gcd+g/TXcMAth+fF5UxY="),
|
"keyId" : NumberLong(0)
|
}
|
}
|
}
|
|