Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a property to existing node neo4j cypher?

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.

like image 480
Kanishka Panamaldeniya Avatar asked Jun 25 '14 11:06

Kanishka Panamaldeniya


People also ask

How do you create a relationship between existing nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.

Can u relabel node in Neo4j?

You can change the nodes associated with a label but you can't change the type of a relationship.

What is the correct syntax to create a node with a property in Neo4j?

In Neo4j, properties are the key-value pairs which are used by nodes to store data. CREATE statement is used to create node with properties, you just have to specify these properties separated by commas within the curly braces "{ }". Syntax: CREATE (node:label { key1: value, key2: value, . . . . . . . . . })

Can a node have multiple labels Neo4j?

Neo4j CQL CREATE a Node Label We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node. That means Neo4j supports only single Relationship Type between two nodes.


1 Answers

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
like image 126
fbiville Avatar answered Sep 23 '22 03:09

fbiville