ArangoDB 动态设置集合时出错

fdbelqdn  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(127)

吹扫代码是对以下内容的微小修改:https://www.arangodb.com/tutorials/tutorial-python/

doc = {"_key": 'some_nice_key', "name": 'Robert', "age": '56'}
bindVars = {"doc": doc,"collection":"test"}
aql = "INSERT @doc INTO @collection LET newDoc = NEW RETURN newDoc"
queryResult = db.AQLQuery(aql, bindVars = bindVars)

我只是做了一些修改:

{"doc": doc}  -> {"doc": doc,"collection":"test"}
INSERT @doc INTO users... -> INSERT @doc INTO @collection...

它给了我错误:

bind parameter 'bind parameter 'collection' has an invalid value or type near '@collection LET newDoc = NEW RET...' at position 1:18' has an invalid value or type (while parsing). Errors: {u'code': 400, u'errorNum': 1553, u'errorMessage': u"bind parameter 'bind parameter 'collection' has an invalid value or type near '@collection LET newDoc = NEW RET...' at position 1:18' has an invalid value or type (while parsing)", u'error': True}

aql不支持动态集合吗?我犯了什么错误?

tquggr8v

tquggr8v1#

AQL支持注入集合名称。但这是一种特殊情况,您必须使用额外的@作为前缀。https://docs.arangodb.com/3.11/aql/fundamentals/bind-parameters/
通过这些修改,您的代码应该可以工作:

doc = {"_key": 'some_nice_key', "name": 'Robert', "age": '56'}
bindVars = {"doc": doc,"@collection":"test"}
aql = "INSERT @doc INTO @@collection LET newDoc = NEW RETURN newDoc"
queryResult = db.AQLQuery(aql, bindVars = bindVars)

相关问题