-1

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.

1 Answer 1

0

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}.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.