Could you tell me how to pass the contents of a variable as a relation name in Neo4j?
My code is:
CREATE (a)-[r:{linkParam}]->(b)
but it does not work.
Basically, you have to options:
(1) Concatenate the string client-side, i.e. create a query string JavaScript that already has the relationship type (e.g. "CREATE (a)-[r:" + linkParam + "]->(b)"
. Note that this might introduce SQL injection-style vulnerabilities in your system.
(2) Use the APOC library:
CALL apoc.create.relationship(a, {linkParam}, b)
This creates a relationship with a dynamic type.
Note that for Neo4j 3.2+, you can use the new parameter syntax, i.e. $linkParam
instead of {linkParam}
.