Prog_G
Prog_G

Reputation: 1615

How to do a group by and then filter on a column in ArangoDB

My object is below :

Document Name: Test

[{
        "_key": "12123",
        "custom_key": "1",
        value = "2"
    }, {
        "_key": "12124",
        "custom_key": "1",
        value = "3"
    }, {
        "_key": "12125",
        "custom_key": "2",
        value = "2"
    }, {
        "_key": "12126",
        "custom_key": "2",
        value = "5"
    }, {
        "_key": "12127",
        "custom_key": "2",
        value = "10"
    }
]

How to write an arango query to get the objects with maximum value group by custom_key?

Upvotes: 0

Views: 62

Answers (1)

mpoeter
mpoeter

Reputation: 2949

Unfortunately, at the moment there is no MAX_BY aggregate function, but as a workaround you can use something like this:

FOR d IN docs
  COLLECT key = d.custom_key AGGREGATE v = MAX([d.value, d])
  RETURN { custom_key: key, doc: v[1] }

Upvotes: 1

Related Questions