简体   繁体   English

无法使用Neo4j REST API动态设置节点标签

[英]Unable to set node label dynamically using the Neo4j REST API

Following the syntax proposed on the Neo4j REST API transactional page , I have tried running the request "CREATE (node:{group} { name: {name}}) RETURN node", { group: "Group", name: "Name"} . 按照Neo4j REST API事务页面上建议的语法,我尝试运行请求"CREATE (node:{group} { name: {name}}) RETURN node", { group: "Group", name: "Name"}

The use of :{group} as a dynamic variable causes an error: :{group}用作动态变量会导致错误:

"Neo.ClientError.Statement.InvalidSyntax","message":"Invalid input '{': expected whitespace or a label name “ Neo.ClientError.Statement.InvalidSyntax”,“消息”:“无效的输入'{':预期的空格或标签名称

Is this pilot error on my part, a bug in the Neo4j query parser, or a something that cannot be done? 这是我的试验性错误,还是Neo4j查询解析器中的错误,或者是无法完成的事情?

Here's my Nodej.s code: 这是我的Nodej.s代码:

var request = require("request")
var host = 'localhost'
  , port = 7474
  , user = "neo4j"
  , pass = "1234"
var uri = 'http://' + user + ":" + pass + "@" + host + ':' + port + '/db/data/transaction/commit'

function runCypherQuery(query, params, callback) {
  request.post({
      uri: uri,
      json: {statements: [{statement: query, parameters: params}]}
    },
    function (err, res, body) {
      callback(err, body)
    })
}

runCypherQuery(
  "CREATE (node:{group} { name: {name}}) RETURN node"
, { group: "Group"
  , name: "Name"
  }
, function (err, resp) {
    if (err) {
      console.log(err)
    } else {
      console.log(JSON.stringify(resp))
    }
  }
)

Node Labels cannot be parameterized in Cypher. 无法在Cypher中参数化节点标签。

Try updating the label in the query as a string instead of passing a parameter: 尝试将查询中的标签更新为字符串而不是传递参数:

"CREATE (node:" + group + " {name: {name}}) RETURN node"

不幸的是,Cypher不支持参数化标签名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM