Multiple SplitInBatches nodes not working

In my workflow am using two SplitInBatches nodes, but the workflow is running only one time. Following the workflow script. Could some one look into this and help me to fix the flow

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        130,
        270
      ],
      "disabled": true
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 1
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        130,
        460
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=select b.id `issueId`, p.name `project`, summary\nfrom mantis_bug_table b\n    inner join mantis_project_table p on p.id = b.project_id\nwhere p.name='{{$node[\"SplitInBatches\"].json[\"mantisProject\"]}}' limit 10;"
      },
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        740,
        460
      ],
      "credentials": {
        "mySql": "MySQL-Mantis"
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        540,
        460
      ]
    },
    {
      "parameters": {
        "collection": "Project"
      },
      "name": "MongoDB",
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1,
      "position": [
        340,
        460
      ],
      "credentials": {
        "mongoDb": "qms-mongo"
      }
    },
    {
      "parameters": {
        "functionCode": "\nconsole.log(items[0].json['issueId'] + ' - ' + items[0].json['project'] + ' - ' + items[0].json['summary'])\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1150,
        460
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches1\"].context[\"noItemsLeft\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1360,
        240
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches1",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        940,
        460
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}"
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1470,
        730
      ]
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "MongoDB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches1": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I just had a quick look and noticed the following:

  1. Why is the SplitInBatches node before the MySQL node? I would guess it’s because you want the MySQL node to be executed per each item returned by the MongoDB node, BUT there is no reference to the MongoDB node in the MySQL, which makes me wonder if that is what you really want.

  2. The SplitinBatches1 node does not seem to be needed. Just use a Function Item node after the MySQL node.

I’m not completely sure of what you want to do. More context will definitely help.

I have project information in MongoDB, for each project related information I have it in MySQL database. I need to pull the information from MySQL for each project and insert into MongoDB if not exists. Am hoping you are clear on my requirement.

Hey @mkiran!

You need to reset the second SplitInBatches node. Click on the Add Option button in the SplitInBatches, and you will see the Reset option. You can use a Set node between MySQL and SplitInBatches1 that sets a property called reset to the value true.

Could you please provide a an example SplitInBatches node with reset option.

Something like that:

It is not working as expected. Second SplitInBatches is not looping through all the records. For example if the MongoDB returns 5 results and the MySQL returns 10 results each time, then in the console it should print 50 logs, but it is printing only 10 logs.

Then it is probably best if you create a separate workflow for the inner loop (so that each of them has only one SplitInBatches-Node) and call it via the Execute Workflow node.