TK36
TK36

Reputation: 11

How to use apoc.periodic.repeat properly?

I am pretty new to Neo4j. I'm trying to update a graph with apoc.periodic.repeat, but it doesn't seem to work. Here is a mock example:

I created more countries than cities to test apoc.periodic.repeat. Then I ran the following:

CALL apoc.periodic.repeat("create-cities", "MATCH (co:Country) MERGE (c:City {name: co.capital})", 1)

This doesn't create new nodes with City label. Here is the result. I'm not sure why it says "false" under done. Can someone please explain why this is not producing the expected outcome? Is there another way to achieve the desired outcome?

EDIT: It turned out that I was using it correctly. I just had some apoc.periodic.iterate jobs running in the background that, I guess, prevented this job from running or perhaps delayed it. I ran :queries and killed all the existing jobs then this job ran as expected.

Upvotes: 0

Views: 352

Answers (1)

Pierre Halftermeyer
Pierre Halftermeyer

Reputation: 11

You may consider the use of apoc.trigger.add.

You first need to enable triggers in apoc.conf file: apoc.trigger.enabled=true

Then you can create the trigger as below.

CALL apoc.trigger.add(
  'create-cities',
  'UNWIND [co IN $createdNodes WHERE id(co) > 0 AND co:Country] AS co
  MERGE (c:City {name: co.capital})',
  {}
);

For testing, the following query should trigger the creation of a Vluatchuk :City node.

MERGE (co:Country {id: "Elbonia", capital: "Vluatchuk"})

Upvotes: 1

Related Questions