2

Im not able to use the params object to name a relationship between 2 nodes ,

Here is the code

var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://localhost:7474');

var params = {
    name: {
        firstname: "SRI",
        lastname: "lanka"
    },
    relname: "country"
};

var query = [
    'MATCH (location:PRIMARY {name:"location"})',
    'CREATE UNIQUE (location)-[:{relname}]->({name})'
].join('\n');

db.query(query, params, function(err, results) {
    if (err) throw err;
    console.log(results);

});

Here is the error.How to make use of the params to name the relationship

Error: Invalid input '{': expected whitespace or a rel type name (line 2, column 28) "CREATE UNIQUE (location)-[:{country}]->({name})"

Karthic Rao
  • 3,624
  • 8
  • 30
  • 44

2 Answers2

3

A relationship type cannot be parameterized. The reason is that a different relationship type might lead to a different query plan.

So you should build up the cypher string using e.g. string concatenation regarding the relationship type and use Cypher parameters where appropriate.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
3

http://docs.neo4j.org/chunked/stable/cypher-parameters.html

Parameters can be used for literals and expressions in the WHERE clause, for the index value in the START clause, index queries, and finally for node/relationship ids. Parameters can not be used as for property names, relationship types and labels, since these patterns are part of the query structure that is compiled into a query plan.

EMR
  • 123
  • 1
  • 9