Inserting multiple replies from chat bot to Mongodb

Since I am still very new to programming and n8n,I have been facing many issues.
How do I get multiple data from user and insert them in Mongodb?
I managed to do it with only one reply but I’m not sure how to do for multiple replies.
@MutedJam @harshil1712 @mcnaveen @Jon
Thanks in advance!!

My workflow:

Hey @ruby09,

The MongoDB node doesn’t support multliple input items so you would need to add a split in batches node before it so you would have something like the below (untested)

Hi! @Jon sorry but I don’t think this helps in my case because, after the first reply is received, the 'If Reply to message" throws a true and the flow stops there. Also I am unsure how to get the expression for Set value because after the first reply is retrieved, the expression cannot be the same right?

I may have misunderstood what you are trying to do then, Each part of the workflow should loop mulitple times depending on the input count. If you only ahve one input from the Telegram Trigger then it will only execute once, If you have 10 it should go 10 times.

If you enable execution logging and check the exection log it should show more about the item counts and a screenshot of that might help show the problem.

Hey @ruby09,

That shows an interesting picture, So you only have one input coming from the tigger, It seems to go up to the switch node but looking at your switch node you don’t have any option to compare with so it isn’t doing anything.

What happens in a switch node is you are telling it that if the value of “Value 1” matches one of the patterns it goes to that output, So if your output 0 was a name you might use regex and have something like ^[a-zA-Z'-]+$ and if output 1 was an email you could use contains @ as very rough examples.


So with that in place in theory it would move to the next step depending on the rule, The tricky bit will be coming up with a rule that works.

Hi @jon , I tried following your advice but I am still not able to insert the variables correctly. Am I doing anything wrong?
My Value 1 for my Switch is not right and when the replied data (Email) goes through the workflow again, it shows true in “IF its a command node”.

Hey @ruby09,

Is it at least routing to the right place now or is it stuck at the same place?

Hi @Jon,
Nope, It is not routing to the right place either

Hey @ruby09,

I suspect then that the values being used are not correct. It might be worth checking those routing rules again or trying an easier rule just to see what happens.

HI @Jon,
Thanks for your help, I managed to figure out what the issue was.

1 Like