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!

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

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.


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

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



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