2016-07-24 66 views
0

吹代碼是稍作修改: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支持動態設置集合還是我做了什麼錯誤?

回答

2

AQL支持注入集合名稱。但這是一個特例,你必須使用額外的@作爲前綴。 https://docs.arangodb.com/3.0/AQL/Fundamentals/BindParameters.html

有了這個修改,您的代碼應工作:

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)