简体   繁体   English

ArangoDB AQL Upsert如何将值推入列表

[英]ArangoDB AQL Upsert how to push a value into list

Trying to use the UPSERT in AQL and successful intill I need to push a value into an list array (and I also need ot check if it exists although I think I have that) 尝试在AQL中使用UPSERT并成功插入,我需要将一个值推入列表数组(并且我还需要ot检查它是否存在,尽管我认为我有)

Code

const t_list_ = db._query(aql`
        UPSERT { token_name: ${token_i}, type: ${type}}
        INSERT { token_name: ${token_i},
                 type: ${type},
                 frequency: ${tokens[i].frequency},
                 user_list: [${req.pathParams.user_id}] }
        UPDATE { frequency: OLD.frequency + ${tokens[i].frequency},
                 user_list: OLD.user_list.push(${req.pathParams.user_id})}
             IN token_category
        RETURN { doc: NEW, type: OLD ? 'update' : 'insert' }`).toArray()

Error is : ArangoError: syntax error, unexpected (, expecting } near '(@value3)} IN token_category 错误是:ArangoError:语法错误,意外(期望在“(@ value3)}附近输入} token_category

The language used here is Javascript. 此处使用的语言是Javascript。 Simplifying the query as used here: 简化此处使用的查询:

let foo="bar";
db._query(aql`RETURN ${foo}`).toArray()

is actually using a specialized AQL-Template string to generate bind values. 实际上是使用专用的AQL-Template字符串来生成绑定值。 To dismantle what is actualy handed into db._query() we may use JSON.stringify() : 要拆除实际交给db._query()我们可以使用JSON.stringify()

print(JSON.stringify(aql`RETURN ${foo}`))
{"query":"RETURN @value0","bindVars":{"value0":"bar"}}

here you see where that string came actually from that was there in the error message: @value3 actually is a bind variable for one of the expressions you've inserted into the template. 在这里,您会看到错误消息中该字符串的实际来源: @value3实际上是您已插入模板中的一个表达式的绑定变量。

So the actual line in question of the syntax error is this one: 因此,有关语法错误的实际问题是:

        UPDATE { frequency: OLD.frequency + ${tokens[i].frequency},
                 user_list: OLD.user_list.push(${req.pathParams.user_id})}

and here you're mixing AQL syntax with Javascript-Syntax, which is not supported. 在这里,您将AQL语法与Javascript-Syntax混合使用,这不受支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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