Java - 无法执行AQL查询

问题描述 投票:0回答:1

如何修复AQL语法错误?我正在尝试使用查询创建边缘,但会出现以下错误:

无法执行查询。响应:400,错误:1501 - AQL:语法错误,位于1:57的'@edges'附近的查询字符串意外结束(解析时)

用于执行查询的代码:

try {

 String query = "INSERT { _from:TurmaA._teste2, _to:TurmaA._testepedro } IN @edges";
 Map<String, Object> bindVars = new MapBuilder().put("edges", nome2).get();
 ArangoCursor<BaseDocument> cursor = arangoDB.db(dbName).query(query, bindVars, 
null, BaseDocument.class);

cursor.forEachRemaining(aDocument -> {
  System.out.println("Key: " + aDocument.getKey());
 });
} catch (ArangoDBException e) {
 System.err.println("Failed to execute query. " + e.getMessage());
}
java arangodb
1个回答
0
投票

请注意collection bind variables have to be prefixed by two @@

所以你的代码示例可能很容易修复如下:


try {

 String query = "INSERT { _from:TurmaA._teste2, _to:TurmaA._testepedro } IN @@edges";
 Map<String, Object> bindVars = new MapBuilder().put("@edges", nome2).get();
 ArangoCursor<BaseDocument> cursor = arangoDB.db(dbName).query(query, bindVars, 
null, BaseDocument.class);

cursor.forEachRemaining(aDocument -> {
  System.out.println("Key: " + aDocument.getKey());
 });
} catch (ArangoDBException e) {
 System.err.println("Failed to execute query. " + e.getMessage());
}
© www.soinside.com 2019 - 2024. All rights reserved.