ArangoDB 将每个不同的元素推送到一个数组
ArangoDB for each distinct push other element to an array
所以我在 ArangoDB 中有一个集合,其中子网分配给团队,我想重新格式化该数据,使每个团队一行一行,其中包含一组分配给他们的子网
集合(Assigment)如下所示:
查询
FOR a IN Assigment
RETURN a
结果
[
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.1.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.2.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.3.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.4.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.5.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.8.0/24",
"team_assignment": "Team5",
"prime_contact": "Anna",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.9.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.10.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.12.0/24",
"team_assignment": "Team5",
"prime_contact": "Anna",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.13.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.15.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.17.0/24",
"team_assignment": "Team7",
"prime_contact": "Erick",
}
]
我想将重新格式化的文档插入不同的集合 (Team_to_Subnet),格式如下:
结果
[
{
"team": "Team1",
"cidrs": ["192.168.1.0/24","192.168.2.0/24","192.168.3.0/24","192.168.13.0/24","192.168.15.0/24"],
"prime_contact": "John"
},
{
"team": "Team2",
"cidrs": ["192.168.4.0/24","192.168.5.0/24","192.168.9.0/24","192.168.10.0/24"],
"prime_contact": "Bob"
},
{
"team": "Team5",
"cidrs": ["192.168.8.0/24","192.168.12.0/24"],
"prime_contact": "Anna"
},
{
"team": "Team7",
"cidrs": ["192.168.17.0/24"],
"prime_contact": "Erick"
},
]
我该怎么做?甚至有可能做到吗?我研究过使用 COLLECT,但我就是想不通。
如有任何帮助,我们将不胜感激
您可以按团队分组并与 COLLECT
联系,并使用 projection expression 获取属于相应组的子集数组:
FOR a IN Assigment
COLLECT team = a.team_assignment, prime_contact = a.prime_contact
INTO cidrs = a.assigment_crteria
RETURN { team, prime_contact, cidrs }
要保存结果,只需将最后一行替换为:
INSERT { team, prime_contact, cidrs } INTO Team_to_Subnet
所以我在 ArangoDB 中有一个集合,其中子网分配给团队,我想重新格式化该数据,使每个团队一行一行,其中包含一组分配给他们的子网
集合(Assigment)如下所示:
查询
FOR a IN Assigment
RETURN a
结果
[
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.1.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.2.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.3.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.4.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.5.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.8.0/24",
"team_assignment": "Team5",
"prime_contact": "Anna",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.9.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.10.0/24",
"team_assignment": "Team2",
"prime_contact": "Bob",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.12.0/24",
"team_assignment": "Team5",
"prime_contact": "Anna",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.13.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.15.0/24",
"team_assignment": "Team1",
"prime_contact": "John",
},
{
"assignment_type": "subnet",
"assigment_crteria": "192.168.17.0/24",
"team_assignment": "Team7",
"prime_contact": "Erick",
}
]
我想将重新格式化的文档插入不同的集合 (Team_to_Subnet),格式如下:
结果
[
{
"team": "Team1",
"cidrs": ["192.168.1.0/24","192.168.2.0/24","192.168.3.0/24","192.168.13.0/24","192.168.15.0/24"],
"prime_contact": "John"
},
{
"team": "Team2",
"cidrs": ["192.168.4.0/24","192.168.5.0/24","192.168.9.0/24","192.168.10.0/24"],
"prime_contact": "Bob"
},
{
"team": "Team5",
"cidrs": ["192.168.8.0/24","192.168.12.0/24"],
"prime_contact": "Anna"
},
{
"team": "Team7",
"cidrs": ["192.168.17.0/24"],
"prime_contact": "Erick"
},
]
我该怎么做?甚至有可能做到吗?我研究过使用 COLLECT,但我就是想不通。
如有任何帮助,我们将不胜感激
您可以按团队分组并与 COLLECT
联系,并使用 projection expression 获取属于相应组的子集数组:
FOR a IN Assigment
COLLECT team = a.team_assignment, prime_contact = a.prime_contact
INTO cidrs = a.assigment_crteria
RETURN { team, prime_contact, cidrs }
要保存结果,只需将最后一行替换为:
INSERT { team, prime_contact, cidrs } INTO Team_to_Subnet