简体   繁体   English

如何将变量作为参数传递给密码查询 (neo4j)

[英]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.

相关问题 使用纯 ZDE9B9ED78D7E2E1DCEEFFEE780E2F919 将 Neo4j cypher 查询结果作为全局 scope 中的变量返回 - Return Neo4j cypher query result as variable in global scope with pure javascript 使用jQuery在Neo4j上执行Cypher查询 - Executing a Cypher query on Neo4j using jQuery 在Neo4j Cypher中处理JSON时如何解决难题? - How to solve the dilemma while handle JSON in Neo4j Cypher? neo4j cypher将不会更新数据库 - neo4j cypher will not update database 如何对Neo4J进行高效,快速的长查询:优化Cypher或改进Javascript / Node.Js构造函数? - How to make an efficient and fast long query for Neo4J: optimize Cypher or improve the Javascript / Node.Js constructor? Neo4j JavaScript驱动程序(bolt)通过id无法工作的Cypher查询=>错误:期望的实体id是一个整数值 - Neo4j JavaScript driver (bolt) Cypher query by id not working => error: Expected entity id to be an integral value Neo4j - 浏览器中的Cypher查询与驱动程序之间的区别? (WITH COLLECT,apoc等) - Neo4j - Difference between Cypher query in Browser vs with Driver? (WITH COLLECT, apoc, etc) 我可以使用JavaScript变量查询Neo4j吗? - Can I use a javascript variable to query Neo4j? 如何将Neo4j查询转换为GraphQL查询? - How to transform a Neo4j Query to a GraphQL query? 来自nodejs的Neo4j多个cypher查询 - Neo4j multiple cypher queries from nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM