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.

Apoc.trigger.add can't work with nested apoc.trigger.nodesbyLabel

I want to achieve a function which can set properties and create a realationship with the existed node when it is triggered by $createNodes params. but ,it seems don't work.
my code is as below:

Blockquote
call apoc.trigger.add('newMatch','unwind apoc.trigger.nodesByLabel($createdNodes,"物品") as node
match (m:可燃物:子类)
where m.name=node.name
set node.burnPoint=m.burnPoint,node.type=m.type
create(node)-[r:isA]->(m)
with node,m
match(n:街道:场景{name:"街道"})
create(n)-[r1:include]->(node)',{phrase:"after"})

The problem is when I use this to create a new node ,there is no property modified and relationship built.

This is my first time to request help in neo4j community, I am looking forward to be replied.

1 ACCEPTED SOLUTION

@zhangjelly66

The problem is that apoc.trigger.nodesByLabel cannot be used together with $createdNodes.
it's supposed to be used with $assignedNode, assignedRelationshipProperties, $removedNode and $removedRelationshipProperties.

In fact, e.g. $assignedNode parameter is a Map<String, List<Node>>, where String is the label, and the function apoc.trigger.nodesByLabel just get the List<Node> to which the label has been assigned, and then you can unwind it.


Instead the $createdNodes parameter is already a List<Node>, therefore you can do directly the unwind.

This should work:

call apoc.trigger.add('newMatch','unwind $createdNodes as node
with node
where "物品" in labels(node)
match (m:可燃物:子类)
where m.name=node.name
set node.burnPoint=m.burnPoint,node.type=m.type
create(node)-[r:isA]->(m)
with node,m
match(n:街道:场景{name:"街道"})
create(n)-[r1:include]->(node)',{phrase:"after"})

View solution in original post

2 REPLIES 2

@zhangjelly66

The problem is that apoc.trigger.nodesByLabel cannot be used together with $createdNodes.
it's supposed to be used with $assignedNode, assignedRelationshipProperties, $removedNode and $removedRelationshipProperties.

In fact, e.g. $assignedNode parameter is a Map<String, List<Node>>, where String is the label, and the function apoc.trigger.nodesByLabel just get the List<Node> to which the label has been assigned, and then you can unwind it.


Instead the $createdNodes parameter is already a List<Node>, therefore you can do directly the unwind.

This should work:

call apoc.trigger.add('newMatch','unwind $createdNodes as node
with node
where "物品" in labels(node)
match (m:可燃物:子类)
where m.name=node.name
set node.burnPoint=m.burnPoint,node.type=m.type
create(node)-[r:isA]->(m)
with node,m
match(n:街道:场景{name:"街道"})
create(n)-[r1:include]->(node)',{phrase:"after"})

Thank you! It works and I understood the reason.