Reputation: 523
It seems I'm unable to create a node with a label based on userinput. I would like to store posted userinput from a form in a variable and pass it on to a Cypher query. While this seems to work fine for properties, it doesn't for labels. I've spend half a day on every possibility like:
('CREATE n:{typeParam} {desc:{descParam}, userID: {IDParam}}) RETURN n', {typeParam:type, descParam: desc, userID: id})
('CREATE n (SET n:{typeParam} {desc:{descParam}, userID: {IDParam}}) RETURN n', {typeParam:type, descParam: desc, userID: id})
('CREATE n:($typeParam) {desc:{descParam}, userID: {IDParam}}) RETURN n', {typeParam:type, descParam: desc, userID: id})
The first character of the the label variable is always seen as invalid input. I really wonder how to do this.
Upvotes: 3
Views: 540
Reputation: 29167
You can use the apoc.create.node
procedure from the APOC library
:
CALL apoc.create.node(
// array of labels
[{typeParam}],
// property object
{
desc: {descParam},
usedID: {userID}
}
)
Upvotes: 6