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

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.

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

3 Likes

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