I have a C# WebAPI in front of my database and a react app that serves as the front end. When I first started using neo4j, I created the api with a HttpPatch method so I could update individual properties. It works for most of the properties, however I was recently notified that it's having problems with single and double quotes within the text. When I pulled it up, I realized immediately what the problem was. I was just simply using a string builder to build out the query to call (I know...it sucks, but I was trying to learn and get things working quickly and now I'm paying for it).
Now, I'm trying to fix it. I found a blog entry from 2016 that explained that neo4j didn't support dynamic properties and I would have to use apoc. Well, since that was 2016 I decided to keep looking and found this as a recommendation on SO:
MATCH (n:Node)
UNWIND keys(n) as key
WITH n,key where key contains 'property.'
SET n['key'] = n['key'] + 1
Based off of that, I created this:
MATCH (p:Person {userId: $userId})
UNWIND keys(p) as key
WITH p, key where key contains $propertyName
SET p[$propertyName] = $propertyValue
I tested it with propertyName of "headline" and propertyValue of "Let's see if this works".
I get the following error:
Neo4j.Driver.V1.ClientException: Invalid input '[': expected an identifier character, whitespace, '{', node labels, a property map, a relationship pattern, '.', '(', '=' or "+=" (line 1, column 108 (offset: 107))
"MATCH (p:Person {userId: $userId}) UNWIND keys(p) as key WITH p, key where key contains $propertyName SET p[$propertyName] = $propertyValue"
What I'm trying to achieve is to be able to pass in a userId, property name and a value and dynamically update the proper node. Is this something that can be done without apoc??? I'm not against using apoc, just haven't had the chance to install it on the server and I've always been a fan of just using the base tools :).
TIA for any help/guidance.
Leeland