31

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.

Paras
  • 253
  • 3
  • 16
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193

1 Answers1

55

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
fbiville
  • 8,407
  • 7
  • 51
  • 79
  • that's Great . it is working , also i want to add surname property to a single Node named user using the ID , please give me a help also for that . Thank you very much – Kanishka Panamaldeniya Jun 25 '14 at 11:51
  • MATCH (n:User) WHERE n.firstname = 'Andres' SET n.surname = 'Taylor' RETURN n – Michael Hunger Jun 25 '14 at 11:52
  • 1
    or MATCH (n:User {firstname:'Andres'}) SET n.surname = 'Taylor' RETURN n – Michael Hunger Jun 25 '14 at 11:52
  • I want to add new property in existing node using csv file , how to do that ? I use this one but it is not working - USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "http://192.168.11.121/movie-reco-db/person_node.csv" AS row MATCH (n:Person) SET n.appId = row.app_id RETURN n – Sachin Vairagi Sep 26 '16 at 12:22