Force items one by one

Hello :raised_hand:

I’m new to N8N and I have a problem with one of my flows.

As you can see from the Item Lists2 I have 12 items and I want that every item gets searched on MongoDB (MongoDB3 - Find), but every time I launch and despite all the steps after, there is only 1 item (the first 1) who get search on MongoDB. How can I force every item to be searched?

If anyone can help me with that, I’ll pay him a cookie.

Thank you in advance,
Have a nice day.

Hey @Growthiste welcome to community!

I love cookies :smiley:

I am pretty sure that mongo node does not support looping yet. You can make the loop yourself, if you have problem upload workflow, and I’ll try to help you :wink:

Hello Shirobachi :slight_smile:

I hope you’re going well and thank you for your answer!

I managed to do looping and it’s working pretty, but I still can’t manage to get the good URL (which is not on our MongoDB) after our IF. I don’t know how to get only the URL that we don’t already have. Of course, when I search for an URL that we don’t have I get a blank json.

Do you have any idea how to fix that please ?

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        1480,
        140
      ]
    },
    {
      "parameters": {
        "url": "https://core.piloterr.com/api/v1/linkedin/similar_companies",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "Bearer "
            }
          ]
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "q",
              "value": "https://www.linkedin.com/company/leslipfrancais/"
            },
            {
              "name": "cookie",
              "value": "AQEDATcpkxs"
            }
          ]
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1740,
        140
      ]
    },
    {
      "parameters": {
        "collection": "tam_linkedin",
        "options": {},
        "query": "={\"regular_company_url\":\"{{$node[\"SplitInBatches\"].json[\"url\"]}}\"}"
      },
      "name": "MongoDB3",
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1,
      "position": [
        2840,
        340
      ],
      "alwaysOutputData": true,
      "credentials": {
        "mongoDb": {
          "id": "2",
          "name": "MongoDB account"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "operation": "aggregateItems",
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "data"
            }
          ]
        },
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        2000,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "name": "Item Lists1",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        2220,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "items",
        "options": {}
      },
      "name": "Item Lists2",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        2440,
        200
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "regular_company_url",
              "value": "={{$node[\"SplitInBatches\"].json[\"url\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        3500,
        -40
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        2640,
        220
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "value": "="
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        3420,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"MongoDB3\"].json[\"regular_company_url\"]}}",
              "value2": "={{$node[\"SplitInBatches\"].json[\"url\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        3180,
        260
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB3": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          },
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Item Lists1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists1": {
      "main": [
        [
          {
            "node": "Item Lists2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists2": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "MongoDB3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}```

Thank you for your help

So LMK where you would like to get URL from. I mean you wrote that URL does not exist in mongoDB

I call an API that gives me URLs, before pushing them to mongoDB I need to be sure that they are not already in the DB. If there a not, I’ll create them into mongoDB.

So I would after get URL make request to mongo and ask for data with that URL, then make if node and in true/false output again mongo node. I’ll try to make something what can help you

@edit @Growthiste
Have a look at this wf, here I used my db what has code props:

LMK if it resolves your problem :wink:

1 Like