apoc.trigger.propertiesByKey

Function APOC Full

Signature

apoc.trigger.propertiesByKey(propertyEntries :: MAP?, key :: STRING?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

propertyEntries

MAP?

null

key

STRING?

null

Usage Examples

This function is used inside a apoc.trigger.add 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.add(
  '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;
Table 1. Results
path

(:Movie {genre: "Crime", title: "The White Tiger"})-[:HAS_GENRE]→(:Genre {name: "Crime"})