[英]How to pass a variable as a parameter to cypher query (neo4j)
I would like to pass a variable (values from request body) as a parameter to the cypher query but i don´t know if (and how) this is possible.我想将变量(来自请求正文的值)作为参数传递给密码查询,但我不知道这是否(以及如何)可能。 I´ve tried few things and a "normal" cypher query with hardcoded string parameter is working perfectly, but when I want to pass the variable as a parameter, I´ll get an error Structure(127, [[object Object]]) .我已经尝试了一些事情,并且带有硬编码字符串参数的“正常”密码查询工作正常,但是当我想将变量作为参数传递时,我会收到错误Structure(127, [[object Object]]) . I´m on Neo4j 3.1.我在 Neo4j 3.1 上。 in combination with a node.js-server which builds the cypher queries.与构建密码查询的 node.js-server 结合使用。
This is a snippet..这是一个片段。。
var user_firstname = req.body.firstname;
var user_lastname = req.body.lastname;
var user_city = req.body.city;
session
.run("CREATE (n:Person {firstname: {firstname}, lastname: {lastname}, city: {city}})",
{ firstname: user_firstname,
lastname: user_lastname,
city: user_city })
Thanks in advance for your help, cheers!在此先感谢您的帮助,干杯!
In Neo4j 3.1 I believe parameter syntax was changed .在 Neo4j 3.1 中,我相信参数语法已更改。 Try using $ before the parameter instead of encasing it in brackets.尝试在参数前使用 $ 而不是将其括在括号中。 See if this query will work instead:看看这个查询是否会起作用:
CREATE (n:Person {firstname: $firstname, lastname: $lastname, city: $city})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.