模板和示例(Templates and examples)#
这里是一些关于 Remove Duplicates 节点 的模板和示例。
🌐 Here are some templates and examples for the Remove Duplicates node.
连续的例子
本节中包含的示例是一个顺序。请按顺序依次进行,以避免意外结果。
模板(Templates)#
使用代码节点设置示例数据(Set up sample data using the Code node)#
创建一个包含示例输入数据的工作流,以测试“删除重复项”节点。
🌐 Create a workflow with some example input data to try out the Remove Duplicates node.
- 在画布上添加一个代码节点,并将其连接到手动触发节点。
- 在代码节点中,将 模式 设置为 每个项目运行一次,并将 语言 设置为 JavaScript。
- 将以下 JavaScript 代码片段粘贴到 JavaScript 字段中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
- 在画布上添加一个拆分输出节点,并将其连接到代码节点。
- 在 Split Out 节点中,在 要拆分的字段 字段中输入
data。
移除当前输入中的重复项(Removing duplicates from the current input)#
- 在画布上添加一个“删除重复项”节点,并将其连接到“拆分输出”节点。选择 在当前输入中删除重复项 作为 操作 来开始。
- 打开“删除重复项”节点,并确保操作设置为删除当前输入中重复的项。
- 在 比较 字段中选择 所有字段。
- 选择 执行步骤 以运行“删除重复项”节点,从当前输入中删除重复的数据。
n8n 会删除在所有字段中数据相同的条目。你的表格视图输出应该如下所示:
🌐 n8n removes the items that have the same data across all fields. Your output in table view should look like this:
| id | name | job | last_updated |
|---|---|---|---|
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
- 再次打开“删除重复项”节点,并将比较参数更改为选定字段。
- 在 要比较的字段 字段中,输入
job。 - 选择 执行步骤 以运行“删除重复项”节点,从当前输入中删除重复的数据。
n8n 会删除当前输入中具有相同 job 数据的项目。你在表格视图中的输出应如下所示:
🌐 n8n removes the items in the current input that have the same job data. Your output in table view should look like this:
| id | name | job | last_updated |
|---|---|---|---|
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
保留值为新值的项(Keep items where the value is new)#
- 打开“删除重复项”节点,并将操作设置为删除在先前执行中已处理的项目。
- 将 保留项目位置 参数设置为 值为新。
- 将 Value to Dedupe On 参数设置为
{{ $json.name }}。 - 在画布上,选择 执行工作流 来运行工作流。打开删除重复项节点以查看结果。
n8n 将当前输入数据与先前执行时存储的项目进行比较。由于这是第一次使用此操作运行“移除重复项”节点,n8n 会处理所有数据项,并将它们放入 保留 输出标签中。项目的顺序可能与输入数据中的顺序不同:
🌐 n8n compares the current input data to the items stored from previous executions. Since this is the first time running the Remove Duplicates node with this operation, n8n processes all data items and places them into the Kept output tab. The order of the items may be different than the order in the input data:
| id | name | job | last_updated |
|---|---|---|---|
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
项目仅与以前的执行进行比较
当前输入项仅与之前执行中存储的项进行比较。这意味着在此操作模式下,当前输入中重复的项不会被删除。如果你需要同时删除当前输入中以及跨执行的重复项,请将两个“删除重复项”节点顺序连接。将第一个设置为使用删除当前输入中重复的项操作,将第二个设置为使用删除之前执行中处理过的项操作。
- 打开代码节点,并取消注释“Tom Hanks”对应的那一行(删除
//)。 - 在画布上,再次选择 执行工作流。再次打开“删除重复项”节点以查看结果。
n8n 将当前输入数据与之前执行中存储的项目进行比较。这一次,保留选项卡中包含来自 Code 节点的一条新记录:
🌐 n8n compares the current input data to the items stored from previous executions. This time, the Kept tab contains the one new record from the Code node:
| id | name | job | last_updated |
|---|---|---|---|
| 9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
丢弃 标签包含先前执行处理的项目:
🌐 The Discarded tab contains the items processed by the previous execution:
| id | name | job | last_updated |
|---|---|---|---|
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
在继续之前,请清除重复历史记录,以便为下一个示例做好准备:
🌐 Before continuing, clear the duplication history to get ready for the next example:
- 打开“删除重复项”节点,并将操作设置为清除去重历史。
- 选择 执行步骤 以清除当前的重复记录。
保留值高于任何先前值的项(Keep items where the value is higher than any previous value)#
- 打开“删除重复项”节点,并将操作设置为删除在先前执行中已处理的项目。
- 将 保留项目位置 参数设置为 值高于任何先前值。
- 将 Value to Dedupe On 参数设置为
{{ $json.id }}。 - 在画布上,选择 执行工作流 来运行工作流。打开删除重复项节点以查看结果。
n8n 将当前输入数据与之前执行时存储的项目进行比较。由于这是在清除历史记录后第一次运行“删除重复项”节点,n8n 会处理所有数据项,并将它们放入 保留 输出标签中。项目的顺序可能与输入数据中的顺序不同:
🌐 n8n compares the current input data to the items stored from previous executions. Since this is the first time running the Remove Duplicates node after clearing the history, n8n processes all data items and places them into the Kept output tab. The order of the items may be different than the order in the input data:
| id | name | job | last_updated |
|---|---|---|---|
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
| 9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
- 打开代码节点,并取消注释“Madonna”和“Bob Dylan”的行(移除
//)。 - 在画布上,再次选择 执行工作流。再次打开“删除重复项”节点以查看结果。
n8n 将当前输入数据与之前执行中存储的项目进行比较。这一次,保留标签中只包含“Bob Dylan”一条记录。n8n 保留该项目是因为其 id 列的值(15)高于之前的任何值(之前的最大值为 9):
🌐 n8n compares the current input data to the items stored from previous executions. This time, the Kept tab contains a single entry for "Bob Dylan." n8n keeps this item because its id column value (15) is higher than any previous values (the previous maximum value was 9):
| id | name | job | last_updated |
|---|---|---|---|
| 15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |
丢弃 标签包含13个项目,其 id 列的值小于或等于之前的最大值(9)。虽然这是新的,但该表仍包含“麦当娜”的条目,因为其 id 值不大于之前的最大值:
🌐 The Discarded tab contains the 13 items with an id column value equal to or less than the previous maximum value (9). Even though it's new, this table includes the entry for "Madonna" because its id value isn't larger than the previous maximum value:
| id | name | job | last_updated |
|---|---|---|---|
| 0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
| 9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
在继续之前,请清除重复历史记录,以便为下一个示例做好准备:
🌐 Before continuing, clear the duplication history to get ready for the next example:
- 打开“删除重复项”节点,并将操作设置为清除去重历史。
- 选择 执行步骤 以清除当前的重复记录。
保留值晚于任何先前日期的项(Keep items where the value is a date later than any previous date)#
- 打开“删除重复项”节点,并将操作设置为删除在先前执行中已处理的项目。
- 将 保留项目位置 参数设置为 值是晚于任何先前日期的日期。
- 将 Value to Dedupe On 参数设置为
{{ $json.last_updated }}。 - 在画布上,选择 执行工作流 来运行工作流。打开删除重复项节点以查看结果。
n8n 将当前输入数据与之前执行时存储的项目进行比较。由于这是在清除历史记录后第一次运行“删除重复项”节点,n8n 会处理所有数据项,并将它们放入 保留 输出标签中。项目的顺序可能与输入数据中的顺序不同:
🌐 n8n compares the current input data to the items stored from previous executions. Since this is the first time running the Remove Duplicates node after clearing the history, n8n processes all data items and places them into the Kept output tab. The order of the items may be different than the order in the input data:
| id | name | job | last_updated |
|---|---|---|---|
| 0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
| 9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
| 15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |
- 打开代码节点,并取消注释“Harry Nilsson”和“Kylie Minogue”的行(删除
//)。 - 在画布上,再次选择 执行工作流。再次打开“删除重复项”节点以查看结果。
n8n compares the current input data to the items stored from previous executions. This time, the Kept tab contains a single entry for "Kylie Minogue." n8n keeps this item because its last_updated column value (2024-10-24T08:03:16.493Z) is later than any previous values (the previous latest date was 2024-10-17T17:11:38.493Z):
| id | name | job | last_updated |
|---|---|---|---|
| 11 | Kylie Minogue | Pop star | 2024-10-24T08:03:16.493Z |
已丢弃 标签包含 15 个项目,这些项目的 last_updated 列值等于或早于之前的最新日期 (2024-10-17T17:11:38.493Z)。尽管它是新的,但此表仍包括 “Harry Nilsson” 的条目,因为其 last_updated 值不晚于之前的最大值:
🌐 The Discarded tab contains the 15 items with a last_updated column value equal to or earlier than the previous latest date (2024-10-17T17:11:38.493Z). Even though it's new, this table includes the entry for "Harry Nilsson" because its last_updated value isn't later than the previous maximum value:
| id | name | job | last_updated |
|---|---|---|---|
| 10 | Harry Nilsson | Singer-songwriter | 2020-10-17T17:11:38.493Z |
| 0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
| 4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
| 5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
| 6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
| 7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
| 8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
| 9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
| 15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |