how to add a property to existing node neo4j cypher?

Kanishka Panamaldeniya picture Kanishka Panamaldeniya · Jun 25, 2014 · Viewed 26.3k times · Source

i have created a new node labeled User

CREATE (n:User)

i want to add a name property to my User node i tried it by

MATCH (n { label: 'User' })
SET n.surname = 'Taylor'
RETURN n

but seems it is not affecting .

how can i add properties to a already created node .

Thank you very much.

Answer

fbiville picture fbiville · Jun 25, 2014

Your matching by label is incorrect, the query should be:

MATCH (n:User)
SET n.surname = 'Taylor'
RETURN n

What you wrote is: "match a user whose label property is User". Label isn't a property, this is a notion apart.

As Michael mentioned, if you want to match a node with a specific property, you've got two alternatives:

MATCH (n:User {surname: 'Some Surname'})

or:

MATCH (n:User)
WHERE n.surname = 'Some Surname'

Now the combo:

MATCH (n:User {surname: 'Some Surname'})
SET n.surname = 'Taylor'
RETURN n