[英]how to insert data with variables in arangodb with python-arango
I try to insert data from a variable and can't find a way to do this, can someone help me?我尝试从变量中插入数据,但找不到这样做的方法,有人可以帮我吗? something like this:
像这样的东西:
name = "mark"
surname = "clark"
db.collection('user').insert([{'username': @name, 'usersurname': @surname}])
thanks!谢谢!
The "db.collection.insert" function is intended to work with objects/arrays, and does not support "variables" as such. “db.collection.insert” function 旨在与对象/数组一起使用,并且不支持“变量”。 In this case, you would use some sort of loop:
在这种情况下,您将使用某种循环:
list_of_persons = [ {name: 'mark', surname: 'clark'} ]
for p in list_of_persons:
db.collection('user').insert({'username': p.name, 'usersurname': p.surname})
Since variables are an AQL construct, they only supported in the query / cursor interface.由于变量是AQL构造,它们仅在查询/ cursor接口中支持。 Here you can specify the variable in the AQL (like
@myVar
) and specify a " bind variable " in the body of the call.在这里,您可以在 AQL 中指定变量(如
@myVar
)并在调用主体中指定“ 绑定变量”。 You will have to read the docs for specific implementation, as they all differ slightly.您必须阅读文档以了解具体实现,因为它们都略有不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.