Skip to main content

$$group

Groups an array of elements into a map of key:array

Usage​

{
"$$group": [ /* values */ ],
"by": /* Transformer */,
"order": /* direction of ordering */,
"type": /* type of values (to order by) */,
"then": [ /* secondary grouping */
{
"by": /* Transformer */,
"order": /* direction of ordering */,
"type": /* type of values (to order by) */,
},
...
]
}
"$$group:{input}"

Returns​

object (Map<String, Array>)

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of elements
byTransformerInput is ##current (current element)YesA transformer to extract a property to group by
orderEnumASC/DESCASCDirection of ordering (ascending / descending)
typeEnumauto/string/number/booleanautoType of values to expect when ordering the input array
thenarrayArray of items containing by,order & typeAn array of subsequent grouping.

Examples​

Input

Definition

Output

[
{ "o": 1, "p": 11, "w":"aaa"},
{ "o": 1, "p": 13, "w":"bbb"},
{ "o": 1, "p": 11, "w":"ccc"},
{ "o": 2, "p": 11, "w":"ddd"},
{ "o": 2, "p": 13, "w":"eee"},
{ "o": 3, "p": 12, "w":"fff"},
{ "o": 1, "p": 9, "w":"zzz"}
]
{
"$$group": "$",
"by": "##current.o",
"then": [
{
"by": {
"$$join": [
"p_",
"##current.p"
]
},
"order": "DESC"
}
]
}
{
"1": {
"p_9": [
{
"o": 1,
"p": 9,
"w": "zzz"
}
],
"p_13": [
{
"o": 1,
"p": 13,
"w": "bbb"
}
],
"p_11": [
{
"o": 1,
"p": 11,
"w": "aaa"
},
{
"o": 1,
"p": 11,
"w": "ccc"
}
]
},
"2": {
"p_13": [
{
"o": 2,
"p": 13,
"w": "eee"
}
],
"p_11": [
{
"o": 2,
"p": 11,
"w": "ddd"
}
]
},
"3": {
"p_12": [
{
"o": 3,
"p": 12,
"w": "fff"
}
]
}
}
[
["a", 1],
["b", true],
["c", "C"],
["c", "D"]
]
"$$group:$"
{
"a": [1],
"b": [true],
"c": ["C", "D"]
}
[
["a", 0, 1],
["a", 1, true],
["a", 2, "C"],
["b", 1, 6]
]
"$$group:$"
{
"a": {
"0": [1],
"1": [true],
"2": ["C"]
},
"b": {
"1": [6]
}
}