简体   繁体   中英

Bind collection in java driver for arangoDB

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM