If I need to filter by array of IDs, how would I do that using bindings? Documentation does not provide any hints on that.
for c in commit
filter c.hash in ['b0a3', '9f0eb', 'f037a0']
return c
If I need to filter by array of IDs, how would I do that using bindings? Documentation does not provide any hints on that.
for c in commit
filter c.hash in ['b0a3', '9f0eb', 'f037a0']
return c
Updating the answer to deal with bindings reference that I missed.
LET commit = [
{ name: "111", hash: "b0a3" },
{ name: "222", hash: "9f0eb" },
{ name: "333", hash: "asdf" },
{ name: "444", hash: "qwer" },
{ name: "555", hash: "f037a0" }
]
FOR c IN commit
FILTER c.hash IN @hashes
RETURN c
The key is that when you send the bind param @hashes
, it needs to be an array, not a string that contains an array.
If you use the AQL Query tool via the ArangoDB Admin Tool, make sure you click the "JSON" button in the top right to ensure the parameter hashes
has the value
["b0a3", "9f0eb", "f037a0"]
and not
"['b0a3', '9f0eb', 'f037a0']"
If you want to send a string as a parameter such as "b0a3","9f0eb","f037a0"
, so { "hashes": "\"b0a3\",\"9f0eb\",\"f037a0\"" }
as bind parameter, then you can split the string into an array like this:
LET commit = [
{ name: "111", hash: "b0a3" },
{ name: "222", hash: "9f0eb" },
{ name: "333", hash: "asdf" },
{ name: "444", hash: "qwer" },
{ name: "555", hash: "f037a0" }
]
FOR c IN commit
FILTER c.hash IN REMOVE_VALUE(SPLIT(@hashes, ['","', '"']), "")
RETURN c
This example will take the string @hashes
and then SPLIT
the contents using ","
and "
as delimiters. This converts the input variable into an array and then the query works as expected. It will also hit an index on the hash
attribute.
The delimiters are enclosed with single quote marks to avoid escaping, which would also be possible but less readable: ["\",\"", "\""]
Note that ","
is listed first as delimiter, so that the result of the SPLIT is
[ "", "9f0eb", "b0a3", "f037a0" ]
instead of
[ "", ",", "9f0eb", "b0a3", "f037a0" ]
.
The empty string element caused by the first double quote mark in the bind parameter value, which would make the query return commit records with an empty string as hash, can be eliminated with REMOVE_VALUE.
The recommended way is to pass ["b0a3", "9f0eb", "f037a0"]
as array however, as shown at the beginning.
c.hash
is just a string. My query is meant to return commits with hashes from within the array of hashes passed as an input parameter. That's why I referred to bindings
, or a use of bind parameters. –
Mer ","
and added REMOVE_VALUE() to get rid of the ""
element as well, which could give you different query results. Also, you don't need to escape the double quotes if you use single quotes in AQL, which is far better readable. –
Moorefield like this:
with person FOR id in ["person/4201061993070840084011","person/1001230840198901011999","person/4201008406196506156918"]
FOR v,e,p In 1..1 ANY id
relation_samefamily,stay,relation_internetbar,relation_flight,relation_train
OPTIONS {
bfs:true
}
FILTER (p.edges[*]._from ALL IN ["person/42010619930708400840084011","person/10012310840989084001011999","person/4201060840196506156918"] and p.edges[*]._to ALL IN ["person/4201061993070808404011","person/1001231908408901011999","person/4200840106196506156918"])
RETURN {v,e}
© 2022 - 2024 — McMap. All rights reserved.
['b0a3', '9f0eb', 'f037a0']
? – Moorefieldfor c in commit filter c.hash in @hashes return c
orfor c in commit filter c.hash in [@hashes] return c
For now my work around is #2, but it looks very dirty on the implementation. – Mer