How to Merge seperated items into a single item

Describe the issue/error/question

Hello,

I’ve been working on content moderation where image URL gets passed to MS Azure content moderator however, its rate limited to 1 URL per sec so I would need to split them into batches and apply a time interval. But after splitting them into batches I have no idea how to merge them back.

I tried using the merge node but it requires two inputs and there’s this one multiplex mode which I’m not sure what to make of it.

I also tried to apply this solution Merging items after "split in batches"


I tried implementing it onto my workflow but looking over it I don’t think it works for strings?

Please share the workflow

Share the output returned by the last node

This is the output I get from the merge function node


I want them to be merged back like this:

Information on your n8n setup

  • n8n version: 0.163.1
  • Database you’re using (default: SQLite): no
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @ReMiKU, the basic idea in the linked thread should still work, even for strings.

The difference to your desired output would be that it creates a single item with an allData field instead of multiple items though.

Here’s a more generic example that would merge the original items:

Example Workflow

You would need to replace HTTP Request in the example Function node’s code with the name of the last node in your loop (so Wait1 if you’re using the workflow from your screenshot, or Set Result1 assuming you want to run this node as part of your loop).

This Function node would run only once and return all items as a single list:

Hope this helps!

1 Like

Hello @MutedJam, thanks for the reply!

You’re right, it indeed works with string! I didn’t think you’d have to revise the function as well to use concat, sweet! and interestingly I also notice you put some arguments within the expression!
image
Now that I’ve read the docs regarding expressions I didn’t know there’s more you could do with it!
those aside, I followed as you suggested however, there’s a slight problem:


The IF node waits up until the second last item instead of the final item then passes twice to the function node. And I think it’s being caused by the wait node :L

The way this works is a bit counterintuitive unfortunately and would happen if the item is passed on to the “wrong” node first.

Could you try connecting the Wait node to the IF node first, then connect the Wait node to the SplitInBatches node?

To illustrate the difference:

SplitInBatches node connected first

IF node connected first

As you can see, the workflows look identical, the only difference is the order in which the connections from the last node of the loop were created.

1 Like

Nani! Σ(゜ロ゜;) wow it really works! just as you said! Tysm

1 Like