# Loop over items

**URL:** <https://community.n8n.io/t/loop-over-items/35794>\
**Category:** Questions\
**Created:** [January 24, 2024, 11:52am UTC](https://community.n8n.io/t/loop-over-items/35794 "2024-01-24T11:52:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 24, 2024, 11:52am UTC](https://community.n8n.io/t/loop-over-items/35794/1 "2024-01-24T11:52:19Z")

</div>

Hello, my question is regarding the loop. My file contains many lines, and I would like to save them in the database every 1000 lines, because when I try to save everything, N8N crashes.

this way it only saves the first 1000 lines.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/a/e/aea97d857e5b2a6784d06e26fe0f1d5dde2bdb6b.png)

## Information on your n8n setup

- **n8n version:** 1.26.0
- **Database (default: SQLite):** default
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Docker.
- **Operating system:** ubuntu

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 24, 2024, 5:25pm UTC](https://community.n8n.io/t/loop-over-items/35794/2 "2024-01-24T17:25:17Z")

</div>

I managed it this way, but it doesn’t solve my problem because I don’t know how many lines there are in the file. Someone help me please?

I increased the number of lines to 5000.

If I don’t set this line limitation, n8n crashes.

---

<div class="post-metadata">

**Author:** ![ihortom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ihortom/32/11473_2.png) [@ihortom](https://community.n8n.io/u/ihortom)\
**Post date:** [January 25, 2024, 2:49am UTC](https://community.n8n.io/t/loop-over-items/35794/3 "2024-01-25T02:49:49Z")

</div>

@miguelraatz ,

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 25, 2024, 11:54am UTC](https://community.n8n.io/t/loop-over-items/35794/4 "2024-01-25T11:54:02Z")

</div>

Hey @ihortom Thanks for the help.

I did it the way you suggested, but for some reason the extract from csv node drops the container, it keeps loading infinitely until the container drops.

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 25, 2024, 2:23pm UTC](https://community.n8n.io/t/loop-over-items/35794/5 "2024-01-25T14:23:56Z")

</div>

The problem I’m facing is related to memory.  
I tried allocating more memory using the variable NODE\_OPTIONS=–max-old-space-size=8192, but it’s still not sufficient. Is there any other way to solve this?  
I would like to split the extract from the file to run in batches of a thousand lines.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 25, 2024, 7:06pm UTC](https://community.n8n.io/t/loop-over-items/35794/6 "2024-01-25T19:06:19Z")

</div>

Hey @miguelraatz,

Have you tried using the offset options in the extract node? So I would maybe save the binary file to disk while you work on it then call a sub worklfow that reads the file and updates mysql then return the number of items of worked on and loop back round to the execute workflow node.

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 25, 2024, 7:34pm UTC](https://community.n8n.io/t/loop-over-items/35794/7 "2024-01-25T19:34:48Z")

</div>

hey @Jon ,

Can you, based on this code, create a visual example for me, please? I’m a beginner and don’t understand the context very well. I’ve been dealing with this issue for three days.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 25, 2024, 8:00pm UTC](https://community.n8n.io/t/loop-over-items/35794/8 "2024-01-25T20:00:58Z")

</div>

Hey @miguelraatz,

I can create a rough visual example but it won’t be a working workflow and you would need to fill in the blanks.

Your main workflow would look like this…

and the workflow it calls would be something like…

These are untested but should give you a good idea of what I was thinking.

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 25, 2024, 9:05pm UTC](https://community.n8n.io/t/loop-over-items/35794/9 "2024-01-25T21:05:51Z")

</div>

Hey @Jon ,  
Thanks for the reply.

I followed all your steps, it seems like a great idea but I’m having issues with this node.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/f/7/f7c42c04f108723d53a3c83565dcdfe3e568aaf3.png)

sub workflow

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 26, 2024, 1:01pm UTC](https://community.n8n.io/t/loop-over-items/35794/10 "2024-01-26T13:01:09Z")

</div>

Hey @miguelraatz,

As mentioned it was never going to just work and was just a rough example for you to fill in the blanks. In this case the error is telling you the node doesn’t exist which is correct as the node is actually called `Execute Workflow Trigger`, I also missed out the `.item` part as well so the correct expression would be something like `{{ $('Execute Workflow Trigger').item.json.startRow }}`.

---

<div class="post-metadata">

**Author:** ![miguelraatz](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@miguelraatz](https://community.n8n.io/u/miguelraatz)\
**Post date:** [January 26, 2024, 1:25pm UTC](https://community.n8n.io/t/loop-over-items/35794/11 "2024-01-26T13:25:09Z")

</div>

Hey @Jon ,  
Thank you for the response, I had already managed to solve it. I am conducting some tests, and as soon as I finish, I will share the solution with anyone who has the same problem.  
Thank you for your patience.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [April 25, 2024, 1:25pm UTC](https://community.n8n.io/t/loop-over-items/35794/12 "2024-04-25T13:25:49Z")

</div>

Closed on April 25, 2024, 1:25pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
