AQL RETURN : array parsing

36 views
Skip to first unread message

Arangogo

unread,
May 30, 2017, 12:25:47 PM5/30/17
to ArangoDB

In AQL how can we parse the result from a RETURN sorting query ?

Our actual collections have many thousands of items : we will limit the resulting array to a short list

For example with only three Objects SX, SY, SW in our collection, with property variable p :

FOR O IN Objects
SORT O.p ASC
RETURN O.name


may return this array :

[
  "SW",
  "SY",
  "SX"
]



Now we want to parse and list the resulting array with visible indexes 1, 2, 3

What is the ID of the array in the database ?

How can we process this returned array directly ?










Jan

unread,
May 30, 2017, 12:53:44 PM5/30/17
to ArangoDB
Hi,

you can try the following:

LET sub = (
  FOR what IN ['SW', 'SY', 'SX'] RETURN what
)
RETURN ZIP(1..LENGTH(sub), sub)

and replace the "sub" subquery with the actual query, which in your case would be

LET sub = (
  FOR O in Objects SORT O.p ASC RETURN O.name
)
RETURN ZIP(1..LENGTH(sub), sub)

Best regards
Jan
Reply all
Reply to author
Forward
0 new messages