[SERVER-14565] New aggregation operators Created: 15/Jul/14  Updated: 20/Mar/15  Resolved: 16/Jul/14

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Ben Rotz Assignee: Ramon Fernandez Marina
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-4588 aggregation: add option to $unwind to... Closed
duplicates SERVER-9625 Support many accumulators in aggregat... Closed
Participants:

 Description   

It would be useful to me if there were a few new operations in the agg framework in the Array Aggregation Operators section (alongside the existing operator $size, perhaps? Or the new $max/$min operators could be alongside the arithmetic operators $add, $multiply, etc.)

//existing operator $size for reference
$size : [1,2,3,3,3]
//returns 5

//NEW operator $selectIndex
//I'm sure there could be different ways to make the syntax work, but here is one example
$selectIndex :

{[1,2,3,3,3] : 4}

//returns 3

//NEW operator $max
//different than existing $max operator which is used in the group stage and only takes one value as a parameter
$max : [1,2,3,3,3]
//returns 3
$max : [$field1, $field2]
//returns the whichever value is greater in field1 or field2

//NEW operator $min
$min: [1,2,3,3,3]
//returns 1
$min : [$field1, $field2]
//returns the whichever value is least in field1 or field2

in particular, the $selectIndex operator would be very valuable to me to convert an array into a simple value, as seen in this mongo google group posting:

https://groups.google.com/forum/#!topic/mongodb-user/qmtAeojf68g



 Comments   
Comment by Asya Kamsky [ 20/Mar/15 ]

nefiga would a $slice array operator in $project allow you to accomplish what you described with your $selectIndex operator?

Comment by Ben Rotz [ 18/Jul/14 ]

While I agree that SERVER-9625 is a duplicate of half of my issue, I don't think that SERVER-4588 is a duplicate of the $selectIndex idea.

I have hundreds of millions of rows in one collection, which have a field that corresponds to a much smaller collection (thousands). I'd love to be able to "join" to this other collection in memory to pull fields that are more dynamic in the smaller collection for purposes of aggregating in a $group stage.

This could easily be done if there was some sort of $selectedIndex in the array operators section of the aggregation framework, right next to $size, because then the array just becomes an in-memory array in a $let clause. Both of these operators can project an array into a single field, which is exactly what I want.

Comment by Ramon Fernandez Marina [ 16/Jul/14 ]

nefiga, similar functionality has already been requested in SERVER-9625 and SERVER-4588. See the former for information on how to accomplish what you need with some helper functions.

Generated at Thu Feb 08 03:35:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.