cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Set the label attributes of all nodes

In "match path=(u)-[*..]-(m) return path", I want to set or limit the label attributes of all nodes in the path, please tell me how to do it 。Thank you very much!

3 REPLIES 3

apankraz
Node Link

Hi, you can access all nodes in the path via

`nodes(p) as nodes

List functions - Neo4j Cypher Manual
and then update all properties of the nodes with a map
SET - Neo4j Cypher Manual

Example:
match path=(u)-[*..]-(m)
with nodes(path) as nodes
unwind nodes as n
SET n = {name: 'Peter Smith', position: 'Entrepreneur'}

this would reset all properties on the nodes with a name and position property. All preexisting properties will be removed.

Bennu
Graph Fellow

Hi,

With Cypher you want something like: (Notice you have no conditions on u. You may like some.

MATCH path=(u)-[*..]-(m) 
WHERE all( n in nodes(path) where n:LabelYouDesire)
return path

With APOC is somethin like

MATCH (u)
WHERE 'INSERT U conditions here'
CALL apoc.path.expandConfig(u, {
	labelFilter: "LABEL_YOU_DESIRE",
    minLevel: 0
})
YIELD path
RETURN path;

H

This is exactly the code I want。Thank you very much!