Reputation: 1421
I'm using java driver for ArangoDB. I have an array of JSONs in a String variable and I want it to be inserted in table. I use the following query
for r in @fromCollection insert r into @targetCollection
In web interface insert goes well, but in Java I'm facing troubles with binding these 2 variables -
1553 - ERROR_QUERY_BIND_PARAMETER_TYPE
Will be raised when a bind parameter has an invalid value or type
Can you help me with binding collection names as variables in ArangoDB?
Upvotes: 3
Views: 500
Reputation: 1891
I am not sure how your JSON String variable plays a role in this query.
When you want to insert the JSON documents included in your String variable you can use the method importDocuments(String)
for that:
ArangoDB arango = new ArangoDB.Builder().build();
arango.db().collection("myCollection").importDocuments(jsonArray);
Related to your problem with your query:
A special type of bind parameter exists for injecting collection names. This type of bind parameter has a name prefixed with an additional @
symbol (thus when using the bind parameter in a query, two @
symbols must be used). For more information about bind parameters take a look here
Your query has to look:
for r in @@fromCollection insert r into @@targetCollection
In Java it looks as follow:
ArangoDB arango = new ArangoDB.Builder().build();
Map<String, Object> bindVars = new HashMap<>();
bindVars.put("@fromCollection", "...");
bindVars.put("@toCollection", "...");
arango.db().query("for r in @@fromCollection insert r into @@targetCollection", bindVars, null, BaseDocument.class)
Upvotes: 3