# Multiple nested apoc.periodic.iterator

**URL:** <https://community.neo4j.com/t/multiple-nested-apoc-periodic-iterator/42522>\
**Category:** Procedures & APOC\
**Tags:** apoc, apocperiodiciterate\
**Created:** [August 6, 2021, 11:13am UTC](https://community.neo4j.com/t/multiple-nested-apoc-periodic-iterator/42522 "2021-08-06T11:13:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![poem\_daga](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/poem_daga/32/5626_2.png) [@poem\_daga](https://community.neo4j.com/u/poem_daga)\
**Post date:** [August 6, 2021, 11:13am UTC](https://community.neo4j.com/t/multiple-nested-apoc-periodic-iterator/42522/1 "2021-08-06T11:13:31Z")

</div>

Question: How to access Node/ Node properties within **multiple nested apoc.periodic.iterator** (s) ?

_to create sample data:_

```auto
:params eventParam=> [{eid: "e1"},{eid: "e2"}];

```

**Query:**

```auto

call apoc.periodic.iterate(
	'
        // create some nodes - *ideally these nodes will be read from some jdbc source*
		UNWIND [1, 2, 3] AS gid
		MERGE (f:FromNode {gid: gid} ) return f 
	',
	' 
       // Run a nested apo.periodic.iterator - procedure to create relationship (FromNode)-[Related]->(Event) - 1 to n relationship
		call apoc.periodic.iterate(
			" unwind $events as ev return ev " , // *ideally events will be derived from (f)'s property
			" merge (f)-[:RELATED_TO]->(e:Event {eid:ev.eid} ) return e ",
			{params:{events: $events}}
		) yield batches return batches

// Note there may be more iterators inside
//call apoc.periodic.iterate(
		//	" unwind $alerts as alert return alert " ,
		//	" merge (f)-[:HAS]->(a:Alert{..} ) return a ",
		//	{params:{alerts: $alerts}}
	//	) yield batches return batches

	',
	{params:{events:$eventParam}, parallel:true}
) 

```

Actual Output:  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/2/6/268315c12b8d7ce6ecf2cfe3dcff33ebbbc03ab1.png)

Expected Output:  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/7/2/725cfcd7516efa6e84bf687275def43a653efc23.png)

**Issue is: _FromNode_ created in first cypherIterator is not accessible in nested iterator while creating relationship**

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [August 20, 2021, 6:48am UTC](https://community.neo4j.com/t/multiple-nested-apoc-periodic-iterator/42522/2 "2021-08-20T06:48:04Z")

</div>

you also need to pass "f" as parameter like you do with events

also best to use id(f) and look up the node/relationship again, as otherwise there might be issues where the tx data of the inner transactions is stored in the main tx.

Also I don't think you need multiple periodic iterates, just use one and move the unwind of the events into the update statement and reduce the batch size.

you should also merge the event in an extra clause otherwise you get one event node per FromNode
