-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Optimization
I would like to be able to use the $out pipeline embedded into the aggregation in multiple locations to snapshot the current output.
Example
[stock] is made up like: { _id:1, type:'widgets', material:'metal', name:'item1', count:5 } { _id:2, type:'widgets', material:'metal', name:'item2', count:3 } { _id:3, type:'widgets', material:'wood', name:'item3', count:2 } { _id:4, type:'widgets', material:'wood', name:'item4', count:5 } { _id:5, type:'widgets', material:'plastic',name:'item5', count:6 } { _id:6, type:'casing', material:'metal', name:'item6', count:0 } { _id:7, type:'casing', material:'wood', name:'item7', count:1 } { _id:8, type:'casing', material:'plastic', name:'item8', count:9 } { _id:9, type:'casing', material:'plastic', name:'item9', count:2 } db.stock.aggregate([ { $group:{ _id: { k1:'$type', k2:'$material' }, totalcount:{$sum:'$count'} } }, { $out:'group_type_material' }, { $group:{ _id: '$_id.k1', totalcount:{$sum:'$totalcount'} } }, { $out:'group_type' }, { $group:{ _id: null, totalcount:{$sum:'$totalcount'} } }, { $out:'group_all' }, ])
which would result in collections of
[group_type_material]: { _id: { k1:'widgets', k2:'metal'}, totalcount:8 } { _id: { k1:'widgets', k2:'wood'}, totalcount:7 } { _id: { k1:'widgets', k2:'plastic'}, totalcount:6 } { _id: { k1:'casing', k2:'metal'}, totalcount:0 } { _id: { k1:'casing', k2:'wood'}, totalcount:1 } { _id: { k1:'casing', k2:'plastic'}, totalcount:11 } [group_type]: { _id: 'widgets', totalcount:21 } { _id: 'casing', totalcount:12 } [group_all]: { _id: null, totalcount:33 }
This would make this aggregation truly powerful in my opinion.
- is duplicated by
-
SERVER-8850 $tee command for aggregation framework
- Closed
-
SERVER-51889 Introduce new stage to peek / debug a pipeline stage's output
- Closed
- is related to
-
SERVER-51889 Introduce new stage to peek / debug a pipeline stage's output
- Closed