AQB: referencing index in array

26 views
Skip to first unread message

Julian May

unread,
Jan 12, 2016, 10:05:18 AM1/12/16
to ArangoDB
Hey

I'm having problems using a declared variable as index for an array within a document.

In AQL i can write


LET myIdx = POSITION(['a','b','n','q'],'n', true)
LET changed = ((changeIdx > -1) ? MERGE(oldDocument.collectionotherDocument.collection[myIdx]) : e) 
RETURN changed


but aqb.ref('otherDocument.collection[myIdx]') fails with the error 


"message": "Not a valid simple reference: changes[myIdx]"


How do i use a reference value as index in a reference array?

Thanks :)

Alan Plum

unread,
Jan 12, 2016, 1:32:55 PM1/12/16
to ArangoDB
Hi Julian,

the easiest way to write AQL in JS is actually to use the aqlQuery template handler provided in ArangoDB and the JS driver:


The reason you're seeing the error is that aqb.ref only supports "simple references", i.e. variable names and property expressions using the dot operator.

If you want to use the square brackets you can do so using the "get" method:

aqb.ref('otherDocument.collection').get('myIdx')


This returns an expression that evaluates to "otherDocument.collection[myIdx]" in AQL.


Cheers,

Alan

Julian May

unread,
Jan 13, 2016, 5:34:16 AM1/13/16
to ArangoDB
Thanks!
Reply all
Reply to author
Forward
0 new messages