Skip to content

比较数据集#

¥Compare Datasets

比较数据集节点可帮助你比较来自两个输入流的数据。

¥The Compare Datasets node helps you compare data from two input streams.

节点参数#

¥Node parameters

  1. 决定要比较哪些字段。在“输入 A”字段中,输入你要使用的输入流 A 中的字段名称。在“输入 B”字段中,输入你要使用的输入流 B 中的字段名称。

¥Decide which fields to compare. In Input A Field, enter the name of the field you want to use from input stream A. In Input B Field, enter the name of the field you want to use from input stream B. 2. 可选的:你可以按多个字段进行比较。选择“添加匹配字段”以设置更多比较。

¥Optional: You can compare by multiple fields. Select Add Fields to Match to set up more comparisons. 3. 选择如何处理数据集之间的差异。在“存在差异时”,选择以下选项之一:

¥Choose how to handle differences between the datasets. In When There Are Differences, select one of the following:

  • 使用“输入 A 版本”将输入流 A 视为真实数据源。

    ¥Use Input A Version to treat input stream A as the source of truth.

  • 使用“输入 B 版本”将输入流 B 视为真实数据源。

    ¥Use Input B Version to treat input stream B as the source of truth.

  • 使用混合版本,为不同的字段使用不同的输入。

    ¥Use a Mix of Versions to use different inputs for different fields.

    • 使用“首选”选项选择输入 A 版本或输入 B 版本作为主要数据源。

    ¥Use Prefer to select either Input A Version or Input B Version as the main source of truth.

    • 输入“除此以外,其余内容均从其他输入源提取”的例外输入字段。要添加多个输入字段,请输入以逗号分隔的列表。

    ¥Enter input fields that are exceptions to For Everything Except to pull from the other input source. To add multiple input fields, enter a comma-separated list.

  • 包含两个版本,以在输出中包含两个输入流,这可能会使结构更复杂。

    ¥Include Both Versions to include both input streams in the output, which may make the structure more complex. 4. 决定是否使用模糊比较。启用此选项后,比较字段时将容忍较小的类型差异。例如,启用模糊比较后,数字 3 和字符串 3 会被视为相同;而禁用模糊比较后,它们则不会被视为相同。

¥Decide whether to use Fuzzy Compare. When turned on, the comparison will tolerate small type differences when comparing fields. For example, the number 3 and the string 3 are treated as the same with Fuzzy Compare turned on, but wouldn't be treated the same with it turned off.

理解项目比较#

¥Understand item comparison

项目比较是一个两阶段过程:

¥Item comparison is a two stage process:

  1. n8n 检查你选择进行比较的字段值在两个输入中是否匹配。

¥n8n checks if the values of the fields you selected to compare match across both inputs. 2. 如果要比较的字段匹配,n8n 将比较项中的所有字段,以确定项是否相同。

¥If the fields to compare match, n8n then compares all fields within the items, to determine if the items are the same or different.

节点选项#

¥Node options

使用节点选项来优化比较或调整比较行为。

¥Use the node Options to refine your comparison or tweak comparison behavior.

要跳过比较的字段#

¥Fields to Skip Comparing

输入要在比较中忽略的字段名称。

¥Enter field names that you want to ignore in the comparison.

例如,如果你使用 person.language 作为匹配字段来比较以下两个数据集,n8n 会返回它们不同的结果。如果你将 person.name 添加到“要跳过比较的字段”中,n8n 会将其返回为匹配项。

¥For example, if you compare the two datasets below using person.language as the Fields to Match, n8n returns them as different. If you add person.name to Fields to Skip Comparing, n8n returns them as matching.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	// Input 1
	[
		{
			"person":
			{
				"name":	"Stefan",
				"language":	"de"
			}
		},
		{
			"person":
			{
				"name":	"Jim",
				"language":	"en"
			}
		},
		{
			"person":
			{
				"name":	"Hans",
				"language":	"de"
			}
		}
	]
	// Input 2
		[
		{
			"person":
			{
				"name":	"Sara",
				"language":	"de"
			}
		},
		{
			"person":
			{
				"name":	"Jane",
				"language":	"en"
			}
		},
		{
			"person":
			{
				"name":	"Harriet",
				"language":	"de"
			}
		}
	]

禁用点号表示法#

¥Disable Dot Notation

是否禁止在字段名称中使用 parent.child 引用子字段(启用)或允许(禁用,默认)。

¥Whether to disallow referencing child fields using parent.child in the field name (turned on) or allow it (turned off, default).

多个匹配项#

¥Multiple Matches

选择如何处理重复数据。默认值为“包含所有匹配项”。你可以选择“仅包含第一个匹配项”。

¥Choose how to handle duplicate data. The default is Include All Matches. You can choose Include First Match Only.

例如,给定以下两个数据集:

¥For example, given these two datasets:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	// Input 1
	[
		{
			"fruit": {
				"type": "apple",
				"color": "red"
			}
		},
				{
			"fruit": {
				"type": "apple",
				"color": "red"
			}
		},
				{
			"fruit": {
				"type": "banana",
				"color": "yellow"
			}
		}
	]
	// Input 2
	[
		{
			"fruit": {
				"type": "apple",
				"color": "red"
			}
		},
				{
			"fruit": {
				"type": "apple",
				"color": "red"
			}
		},
				{
			"fruit": {
				"type": "banana",
				"color": "yellow"
			}
		}
	]

n8n 会在“同一分支”选项卡中返回三个项。两个分支中的数据相同。

¥n8n returns three items in the Same Branch tab. The data is the same in both branches.

如果你选择“仅包含第一个匹配项”,n8n 将在“同一分支”选项卡中返回两个项目。两个分支中的数据相同,但 n8n 仅返回匹配的 "apple" 项的第一个实例。

¥If you select Include First Match Only, n8n returns two items, in the Same Branch tab. The data is the same in both branches, but n8n only returns the first occurrence of the matching "apple" items.

理解输出#

¥Understand the output

有四种输出选项:

¥There are four output options:

  • 仅在 A​​ 分支中:包含仅在第一个输入中出现的数据。

¥In A only Branch: Contains data that occurs only in the first input.

  • 同一分行:包含在两个输入中相同的数据。

¥Same Branch: Contains data that's the same in both inputs.

  • 不同分支:包含在两个输入中不同的数据。

¥Different Branch: Contains data that's different between inputs.

  • 仅在 B 分支中:包含仅在第二个输出中出现的数据。

¥In B only Branch: Contains data that occurs only in the second output.

模板和示例#

¥Templates and examples

Template widget placeholder.