如何将集合名称和文档密钥传递到 AQL 查询以更新文档

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

从 Windows 10 桌面环境中具有本地 ArangoDB 数据库的 Appsmith,无法获取 AQL 查询来识别从 Appsmith 输入小部件传入的集合名称。如果集合名称硬编码到查询中,并在 LET、IN 等语句中尝试 @@、@、${} 等的每个组合以使集合名称被接受,则可以工作。

此代码适用于硬编码的集合名称:

    LET artiKey = "{{TestITartiKey.text}}"LET comSequ = 0
    LET Comment = \[
    {
    "comSequ": 0,
    "comment": "{{InpITcomment.text}}"  
    }
    \]

    FOR doc IN paeAnalysisAttributesNouns
    FILTER doc.\_key == artiKey
    UPDATE artiKey WITH {
    "comSequ": 0,
    Comments: UNION( doc.Comments, Comment )
    }
    IN paeAnalysisAttributesNouns
    RETURN doc

许多不起作用的版本之一:

    LET @@artiColVar = {{TestITartiColl.text}}
    LET artiKey = {{TestITartiKey.text}}

    LET artiCol = artiColVar
    LET comSequ = 0
    LET Comment = \[
    {
    "comSequ": 0,
    "comment": "{{InpITcomment.text}}"
    }
    \]

    FOR doc IN @artiColVar
    FILTER doc.\_key == artiKey
    UPDATE artiKey WITH {
    "comSequ": 0,
    Comments: UNION( doc.Comments, Comment)
    IN @artiColVar }
    RETURN doc

出现以下错误消息:

Your query failed to execute:
com.arangodb.ArangoDBException: Response: 400, Error: 1501 - AQL: syntax error, unexpected bind data source parameter, expecting identifier near '@@artiColVar = paeAnalysisAttrib...' at position 3:5 (while parsing)
{
"actionId":"65fc10a82f6b8a5a1dbb647d"
"requestedAt":"2024-03-21 12:46:05"
"requestParams":{
"Query":{
"value":"//Q2AB1FirstComment LET @@artiColVar = paeAnalysisAttributesNouns LET artiKey = 5095442 LET artiCol = artiColVar LET comSequ = 0 LET Comment = \[ { "comSequ": 0, "comment": "Results in two Account entries" } \] FOR doc IN @artiCol FILTER doc.\_key == artiKey UPDATE artiKey WITH { "comSequ": 0, Comments: UNION( doc.Comments, Comment ) IN @artiCol } RETURN doc "
}
}
}

欢迎任何评论和帮助 - 这似乎是一个需要能够做到的基本查询!

期望的结果: 要将注释对象添加到传入的集合名称、文档数组字段,当集合名称硬编码到 AQL 查询中时,该注释对象可以完美运行。

dynamic collections arangodb aql appsmith
1个回答
0
投票

对 appsmith 不太熟悉,但您可以使用字符串连接作为解决方法,例如:

let artiColVar = TestITartiColl.text; // Init the collection name based on the appsmith 

let query = `
    //...
    FOR doc IN ${artiColVar}

`

确保对输入进行消毒,以避免 Aql 注入。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.