3

I'm facing some issues when trying to bind a list variable in an ArangoDB query. More concretely, the list might look like as follows and comes from a URL parameter in a certain Foxx controller endpoint:

.../someAPIEndpoint?list=A,B,C,D

I would like to be able to do something like this:

stmt = db._createStatement({query: "for i in [@list] return i"});
stmt.bind('list', req.params('list').split(','));

Since I do not know how many values will I receive from the API call, I can't create n bindings for each possible one. Is what I want to achieve even possible?

Thanks in advance.

1 Answer 1

2

you were almost there, you can bind an array directly to the parameter (i just removed "[" and "]" from your query:

stmt = db._createStatement({query: "for i in @list return i"});
stmt.bind('list', req.params('list').split(','));
Sign up to request clarification or add additional context in comments.

2 Comments

Hi @mchacki, thanks for your quick reply. I also tried that way, but I get ERROR A runtime error occurred while executing an action: [ArangoError 1563: list expected] Error: list expected. Is there out any way to check what AQL query is actually being tried to be executed? I checked the stmtobject but bindings are not interpolated.
you could use stmt.explain() to get some information about your query. Look for something like: { "id" : 1, "loopLevel" : 1, "type" : "for", "resultVariable" : "i", "expression" : { "type" : "const value", "value" : "\"A,B,C,D\"" } }, in this case i have bound a string instead of an array to @list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.