How to filter 2 lists of items for uniques based on key/value?

I’m getting a list from RSS and another list from Mongo. I need to filter all items that don’t exist in Mongo and then process them. What would be the solution to this?

Workflow Goal:

  1. Read RSS feed
  2. Filter by keywords
  3. Check if article link already exist in the database
  4. If (not found)
  5. Insert to db
  6. Send to a webhook

What I’ve Tried:

I attempted to pass input data from Node 2 to Node 4 at the same time as Node 3 to Node 4 to check against but I can’t seem to extract key/values and merge them into a single array variable. This causes items from List A to be checked against one criteria only from List B resulting in false positives

Is it possible to use a Function node to compare 2 items lists?

Or have Mongo/Postgres continue if nothing is found? With number of rows/items found for Context would be helpful too

Sadly there was no simple way to do that. Even though there obviously should be. For that reason did I extend the Merge-Node and added the modes “Keep Key Matches” and “Remove Key Matches”.

Just released [email protected] which contains the additions. Now it is simply possible like that (you can simply copy&paste the JSON bellow into n8n):

{
  "nodes": [
    {
      "parameters": {
        "url": "https://www.feedforall.com/sample.xml"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "mode": "removeKeyMatches",
        "propertyName1": "isoDate",
        "propertyName2": "date"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        650,
        400
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      date: '2004-10-19T15:09:11.000Z'\n    }\n  },\n  {\n    json: {\n      date: '2004-10-19T15:09:09.000Z'\n    }\n  }\n];"
      },
      "name": "Fake DB Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        500
      ]
    }
  ],
  "connections": {
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fake DB Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}
1 Like

Perfect! :tada: My workflow is operating as intended. I’ll be having a lot of fun with this :blush:

Here is the link to my published workflow https://n8n.io/workflows/159

2 Likes

Just a heads up, some modes were mislabeled for the Merge node during a recent update. Keep Key Matches and Remove Key Matches are reversed

@dave0 I just checked if anything got mislabeled. Was however not the case. So I did check the functionality and also that worked fine. Here an example workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://www.feedforall.com/sample.xml"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "isoDate",
        "propertyName2": "date"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        650,
        400
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      date: '2004-10-19T15:09:11.000Z'\n    }\n  },\n  {\n    json: {\n      date: '2004-10-19T15:09:09.000Z'\n    }\n  }\n];"
      },
      "name": "Fake DB Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        500
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "RSS Feed Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fake DB Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}

If in “Keep Key Matches” it outputs 2 items. As only two dates match. If in “Remove Key Matches” it outputs 7 (there were 9 originally, 2 did match so 7 were left). So it seems to work perfectly.

So the only thing I can imagine right now is that you may be misunderstanding how the node works. It is not important if the values in “Property Input 1&2” match, what matters is if the values which get found for that keys match.

1 Like

I double checked my workflow, you are correct. I was using an expression instead of key name

The confusion arose due to having 2 installations of n8n though it still worked using the Merge node in an unintended way which is interesting to say the least

Sorry for the trouble. Thanks for looking into this for me

Ah great to hear that it works now.

Nothing to be sorry for. It is partly my fault as I did not find the time yet to create documentation for the Merge-Node. I really hope I get to that soon. Sorry!

1 Like