# Remove node when url already exists

**URL:** <https://forum.alumio.com/t/remove-node-when-url-already-exists/1350>\
**Category:** Data Transformers\
**Created:** [October 23, 2024, 7:10am UTC](https://forum.alumio.com/t/remove-node-when-url-already-exists/1350 "2024-10-23T07:10:42Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [October 25, 2024, 2:21pm UTC](https://forum.alumio.com/t/remove-node-when-url-already-exists/1350/3 "2024-10-25T14:21:30Z")

</div>

Hi @yoeri,

Please follow the below steps to achieve your objective.

For instance, you have the below entity:

```auto
{
  "shopifyProduct": {
    "images": {
      "nodes": [
        {
          "url": "<url>/files/40785087-1.jpg?v=1729606668"
        },
        {
          "url": "<url>/files/40785087-2.jpg?v=1729606668"
        }
      ]
    }
  },
  "media": [
    {
      "originalSource": "<url>/16411820149/40785087-1.jpg"
    },
    {
      "originalSource": "<url>/16411820150/40785087-3.jpg"
    }
  ]
}

```

1. First, copy the URLs of the existing media to a separate array, i.e., `existingMedia`, using [Copy using a pattern](https://forum.alumio.com/t/copy-using-a-pattern/276).

2. Fetch only the filename within the URLs using [String: File basename](https://forum.alumio.com/t/how-to-get-filename-from-a-path-string/154) mapper, and remove the version parameter using [String: PCRE replace](https://forum.alumio.com/t/how-to-replace-everything-from-string-with-pcre-regex-result/155) and “String: Replace”.

3. Copy the array of the formatted URLs to each object in the `media` array using [Recursively copy values to children](https://forum.alumio.com/t/recursively-copy-values-to-children/287).

4. Loop into the `media` array by using “Node, transform nodes”. If you can’t find the entity transformer, it means that you are inside a “Data, transform nodes using mappers and conditions”. Then, you can use [Execute entity transformers](https://forum.alumio.com/t/how-to-use-execute-entity-transformers/993) first, and then select “Node, transform nodes”, as shown below.

5. Within each object, create a new variable that holds the filename within the URL (`originalSource`) using the [String: File basename](https://forum.alumio.com/t/how-to-get-filename-from-a-path-string/154) mapper (point 1 in the picture below).

6. Since each object has the list of media file names that exist in Shopify (as a result of Step 3), you can now check whether the current media file name (`file`) exists in the existing list (`existingMedia`) using JMESPath function [`contains`](https://jmespath.org/specification.html#contains) (point 2 in the picture below).

7. All objects in the media now have a property `exists: true/false.` Leave the loop and use a Value Setter and JMESPath query to filter out the ones with `exists: true`.

The result of the above transformers is the entity below:

```auto
{
  "shopifyProduct": {
    "images": {
      "nodes": [
        {
          "url": "<url>/files/40785087-1.jpg?v=1729606668"
        },
        {
          "url": "<url>/files/40785087-2.jpg?v=1729606668"
        }
      ]
    }
  },
  "media": [
    {
      "originalSource": "<url>/16411820150/40785087-3.jpg"
    }
  ],
  "existingMedia": [
    "40785087-1.jpg",
    "40785087-2.jpg"
  ]
}

```

We hope our explanation is clear to you. We also created a sample entity transformer of the above steps below.

[export\_20241025161824.ndjson](https://forum.alumio.com/uploads/short-url/9sUtMaVoAq2Mb2hWj2OHSaZLPiP.ndjson) (2.2 KB)

Feel free to let us know if you have any questions.

---

_[View the full topic](https://forum.alumio.com/t/remove-node-when-url-already-exists/1350)._
