Skip to content

模板和示例#

¥Templates and examples

以下是 移除重复节点 的一些模板和示例。

¥Here are some templates and examples for the Remove Duplicates node.

Continuous examples

本节中包含的示例是一系列的。请按步骤操作,以避免出现意外结果。

¥The examples included in this section are a sequence. Follow from one to another to avoid unexpected results.

模板#

¥Templates

Template widget placeholder.

使用代码节点设置示例数据#

¥Set up sample data using the Code node

创建一个包含示例输入数据的工作流,以测试“删除重复项”节点。

¥Create a workflow with some example input data to try out the Remove Duplicates node.

  1. 在画布上添加一个代码节点,并将其连接到手动触发节点。

¥Add a Code node to the canvas and connect it to the Manual Trigger node. 2. 在“代码”节点中,将“模式”设置为“每个项目运行一次”,并将“语言”设置为“JavaScript”。

¥In the Code node, set Mode to Run Once for Each Item and Language to JavaScript. 3. 将以下 JavaScript 代码片段粘贴到“JavaScript”字段中:

¥Paste the following JavaScript code snippet in the JavaScript field:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
let data =[];

return {
  data: [
    { id: 1, name: 'Taylor Swift', job: 'Pop star', last_updated: '2024-09-20T10:12:43.493Z' },
    { id: 2, name: 'Ed Sheeran', job: 'Singer-songwriter', last_updated: '2024-10-05T08:30:59.493Z' },
    { id: 3, name: 'Adele', job: 'Singer-songwriter', last_updated: '2024-10-07T14:15:59.493Z' },
    { id: 4, name: 'Bruno Mars', job: 'Singer-songwriter', last_updated: '2024-08-25T17:45:12.493Z' },
    { id: 1, name: 'Taylor Swift', job: 'Pop star', last_updated: '2024-09-20T10:12:43.493Z' },  // duplicate
    { id: 5, name: 'Billie Eilish', job: 'Singer-songwriter', last_updated: '2024-09-10T09:30:12.493Z' },
    { id: 6, name: 'Katy Perry', job: 'Pop star', last_updated: '2024-10-08T12:30:45.493Z' },
    { id: 2, name: 'Ed Sheeran', job: 'Singer-songwriter', last_updated: '2024-10-05T08:30:59.493Z' },  // duplicate
    { id: 7, name: 'Lady Gaga', job: 'Pop star', last_updated: '2024-09-15T14:45:30.493Z' },
    { id: 8, name: 'Rihanna', job: 'Pop star', last_updated: '2024-10-01T11:50:22.493Z' },
    { id: 3, name: 'Adele', job: 'Singer-songwriter', last_updated: '2024-10-07T14:15:59.493Z' },  // duplicate
    //{ id: 9, name: 'Tom Hanks', job: 'Actor', last_updated: '2024-10-17T13:58:31.493Z' },
    //{ id: 0, name: 'Madonna', job: 'Pop star', last_updated: '2024-10-17T17:11:38.493Z' },
    //{ id: 15, name: 'Bob Dylan', job: 'Folk singer', last_updated: '2024-09-24T08:03:16.493Z'},
    //{ id: 10, name: 'Harry Nilsson', job: 'Singer-songwriter', last_updated: '2020-10-17T17:11:38.493Z' },
    //{ id: 11, name: 'Kylie Minogue', job: 'Pop star', last_updated: '2024-10-24T08:03:16.493Z'},
  ]
}
  1. 在画布上添加一个拆分输出节点,并将其连接到代码节点。

¥Add a Split Out node to the canvas and connect it to the Code node. 5. 在“拆分”节点中,在“要拆分的字段”字段中输入 data

¥In the Split Out node, enter data in the Fields To Split Out field.

移除当前输入中的重复项#

¥Removing duplicates from the current input

  1. 在画布上添加一个删除重复项节点,并将其连接到拆分输出节点。选择“删除当前输入中重复的项目”作为启动操作。

¥Add a Remove Duplicates node to the canvas and connect it to the Split Out node. Choose Remove items repeated within current input as the Action to start. 2. 打开“删除重复项”节点,并确保“操作”设置为“删除当前输入中重复的项目”。

¥Open the Remove Duplicates node and ensure that the Operation is set to Remove Items Repeated Within Current Input. 3. 在“比较”字段中选择“所有字段”。

¥Choose All fields in the Compare field. 4. 选择“执行步骤”可运行“删除重复项”节点,删除当前输入中的重复数据。

¥Select Execute step to run the Remove Duplicates node, removing duplicated data in 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 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z
  1. 再次打开“删除重复项”节点,并将“比较”参数更改为“选定字段”。

¥Open the Remove Duplicates node again and change the Compare parameter to Selected Fields. 6. 在“要比较的字段”字段中,输入 job

¥In the Fields To Compare field, enter job. 7. 选择“执行步骤”可运行“删除重复项”节点,删除当前输入中的重复数据。

¥Select Execute step to run the Remove Duplicates node, removing duplicated data in the current input.

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 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z

保留值为新值的项#

¥Keep items where the value is new

  1. 打开“删除重复项”节点,并将“操作”设置为“删除先前执行中处理的项目”。

¥Open the Remove Duplicates node and set the Operation to Remove Items Processed in Previous Executions. 2. 将“保留项条件”参数设置为“值是新值”。

¥Set the Keep Items Where parameter to Value Is New. 3. 将“去重条件”参数的值设置为 {{ $json.name }}

¥Set the Value to Dedupe On parameter to {{ $json.name }}. 4. 在画布上,选择“执行工作流”以运行工作流。打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow to run the workflow. Open the Remove Duplicates node to examine the results.

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 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z

Items are only compared against previous executions

当前输入项仅与先前执行中存储的项进行比较。这意味着,在此操作模式下,当前输入中重复的项不会被删除。如果需要删除当前输入中以及跨执行的重复项,请将两个“删除重复项”节点依次连接在一起。将第一个字段设置为使用“移除当前输入中重复的项目”操作,将第二个字段设置为使用“移除先前执行中处理的项目”操作。

¥The current input items are only compared against the stored items from previous executions. This means that items repeated within the current input aren't removed in this mode of operation. If you need to remove duplicate items within the current input and across executions, connect two Remove Duplicate nodes together sequentially. Set the first to use the Remove Items Repated Within Current Input operation and the second to use the Remove Items Processed in Previous Executions operation.

  1. 打开代码节点,并取消注释(删除 //)"汤姆·汉克斯" 对应的行。

¥Open the Code node and uncomment (remove the // from) the line for "Tom Hanks." 6. 在画布上,再次选择“执行工作流”。再次打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow again. Open the Remove Duplicates node again to examine the results.

n8n 将当前输入数据与先前执行中存储的数据进行比较。此时,“保留”选项卡包含来自“代码”节点的一个新记录:

¥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 汤姆·汉克斯 参与者 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 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z

在继续之前,请清除重复历史记录,以便为下一个示例做好准备:

¥Before continuing, clear the duplication history to get ready for the next example:

  1. 打开“删除重复项”节点,并将“操作”设置为“清除去重历史记录”。

¥Open the Remove Duplicates node and set the Operation to Clear Deduplication History. 8. 选择“执行步骤”可清除当前重复项历史记录。

¥Select Execute step to clear the current duplication history.

保留值高于任何先前值的项#

¥Keep items where the value is higher than any previous value

  1. 打开“删除重复项”节点,并将“操作”设置为“删除先前执行中处理的项目”。

¥Open the Remove Duplicates node and set the Operation to Remove Items Processed in Previous Executions. 2. 将“保留项条件”参数设置为“值高于任何先前值”。

¥Set the Keep Items Where parameter to Value Is Higher than Any Previous Value. 3. 将“去重条件”参数的值设置为 {{ $json.id }}

¥Set the Value to Dedupe On parameter to {{ $json.id }}. 4. 在画布上,选择“执行工作流”以运行工作流。打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow to run the workflow. Open the Remove Duplicates node to examine the results.

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 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z
9 汤姆·汉克斯 参与者 2024-10-17T13:58:31.493Z
  1. 打开代码节点,并取消注释(删除 //)"Madonna" 和 "鲍勃·迪伦。" 对应的行。

¥Open the Code node and uncomment (remove the // from) the lines for "Madonna" and "Bob Dylan." 6. 在画布上,再次选择“执行工作流”。再次打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow again. Open the Remove Duplicates node again to examine the results.

n8n 将当前输入数据与先前执行中存储的数据进行比较。此时,“保留”选项卡包含 "鲍勃·迪伦。" 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 鲍勃·迪伦 民谣歌手 2024-09-24T08:03:16.493Z

“已丢弃”标签页包含 13 个 id 列值等于或小于先前最大值 (9) 的项目。尽管它是新的,但此表包含 "Madonna" 的条目,因为它的 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 流行歌星 2024-10-17T17:11:38.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z
9 汤姆·汉克斯 参与者 2024-10-17T13:58:31.493Z

在继续之前,请清除重复历史记录,以便为下一个示例做好准备:

¥Before continuing, clear the duplication history to get ready for the next example:

  1. 打开“删除重复项”节点,并将“操作”设置为“清除去重历史记录”。

¥Open the Remove Duplicates node and set the Operation to Clear Deduplication History. 8. 选择“执行步骤”可清除当前重复项历史记录。

¥Select Execute step to clear the current duplication history.

保留值晚于任何先前日期的项#

¥Keep items where the value is a date later than any previous date

  1. 打开“删除重复项”节点,并将“操作”设置为“删除先前执行中处理的项目”。

¥Open the Remove Duplicates node and set the Operation to Remove Items Processed in Previous Executions. 2. 将“保留项条件”参数设置为“值是晚于任何先前日期的日期”。

¥Set the Keep Items Where parameter to Value Is a Date Later than Any Previous Date. 3. 将“去重条件”参数的值设置为 {{ $json.last_updated }}

¥Set the Value to Dedupe On parameter to {{ $json.last_updated }}. 4. 在画布上,选择“执行工作流”以运行工作流。打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow to run the workflow. Open the Remove Duplicates node to examine the results.

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 流行歌星 2024-10-17T17:11:38.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z
9 汤姆·汉克斯 参与者 2024-10-17T13:58:31.493Z
15 鲍勃·迪伦 民谣歌手 2024-09-24T08:03:16.493Z
  1. 打开代码节点,并取消注释(删除 //)"Harry Nilsson" 和 "Kylie Minogue." 对应的行。

¥Open the Code node and uncomment (remove the // from) the lines for "Harry Nilsson" and "Kylie Minogue."

  1. 在画布上,再次选择“执行工作流”。再次打开“删除重复项”节点以查看结果。

¥On the canvas, select Execute workflow again. Open the Remove Duplicates node again to examine the results.

n8n 将当前输入数据与先前执行中存储的数据进行比较。此时,“保留”选项卡包含 "Kylie Minogue." n8n 的一个条目,保留此条目是因为其 last_updated 列的值 (2024-10-24T08:03:16.493Z) 晚于任何先前的值(先前的最新日期为 2024-10-17T17:11:38.493Z):

¥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 流行歌星 2024-10-24T08:03:16.493Z

“已丢弃”标签页包含 last_updated 列值等于或早于上一个最新日期 (2024-10-17T17:11:38.493Z) 的 15 个项目。尽管它是新的,但此表包含 "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 创作歌手 2020-10-17T17:11:38.493Z
0 Madonna 流行歌星 2024-10-17T17:11:38.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
1 Taylor Swift 流行歌星 2024-09-20T10:12:43.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
2 艾德·希兰 创作歌手 2024-10-05T08:30:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
3 Adele 创作歌手 2024-10-07T14:15:59.493Z
4 Bruno Mars 创作歌手 2024-08-25T17:45:12.493Z
5 Billie Eilish 创作歌手 2024-09-10T09:30:12.493Z
6 凯蒂·佩里 流行歌星 2024-10-08T12:30:45.493Z
7 Lady Gaga 流行歌星 2024-09-15T14:45:30.493Z
8 蕾哈娜 流行歌星 2024-10-01T11:50:22.493Z
9 汤姆·汉克斯 参与者 2024-10-17T13:58:31.493Z
15 鲍勃·迪伦 民谣歌手 2024-09-24T08:03:16.493Z