apoc.trigger.propertiesByKey
Function APOC Full
This procedure is not intended to be used in a cluster environment, and may act unpredictably. |
Usage Examples
This function is intended to be used within an apoc.trigger.install Cypher statement.
We can use it to conditionally run Cypher statements when properties are added or removed.
For example, we can connect nodes with a genre
property to a Genre
node, with the following trigger:
CALL apoc.trigger.install(
'neo4j',
'triggerTest',
'UNWIND apoc.trigger.propertiesByKey($assignedNodeProperties, "genre") as prop
WITH prop.node as n
MERGE (g:Genre {name: n.genre})
MERGE (n)-[:HAS_GENRE]->(g)
',
{}
);
Let’s now create a Movie
node with a genre
property:
CREATE (:Movie {title: "The White Tiger", genre: "Crime"});
And now let’s find all HAS_GENRE
relationships:
MATCH path = ()-[:HAS_GENRE]->()
RETURN path;
path |
---|
(:Movie {genre: "Crime", title: "The White Tiger"})-[:HAS_GENRE]→(:Genre {name: "Crime"}) |