Obtaining maximun _key value from an Arango Collection

80 Views Asked by At

Imagine that _key is a series which is always increasing, such as:

{
  _key:1,
  name: John,
  ...
},
{
  _key:2,
  name ...
},
...

I would like to get the maximum value of _key so I can include another element with a _key + 1 value.

I am using python-arango but I could collect the AQL query too.

1

There are 1 best solutions below

0
On

To get the largest numerical _key value of collection coll so far:

      FOR c IN coll
        COLLECT AGGREGATE maxk = MAX(c._key)
        RETURN {max_coll_key: TO_NUMBER(maxk)}