如何将节点属性转换为虚拟节点并生成[虚拟]关系?
我目前正在学习密码,但试图找出如何完成以下任务。
我的数据
Neo4j 中有一组具有属性的节点。这些属性很少使用,因此拥有实际的节点没有多大意义。我下面的示例是具有名称和大陆属性的国家/地区节点列表。我们不经常使用大陆,但它仍然是为了提供信息而存在。
[
{
name: "Australia",
continent: "Oceania"
},
{
name: "Canada",
continent: "North America"
},
{
name: "New Zealand",
continent: "Oceania"
},
{
name: "United States",
continent: "North America"
}
]
我想要的
我们希望生成的是每个大陆的虚拟节点+关系,这样我们就可以看到哪些国家属于哪些大陆。因此,每个大陆一个节点,每个国家一个节点,具有从单个大陆到其内国家的多种关系。
我所拥有的
到目前为止我所拥有的如下 - 但它只是为我找到的每个大陆值提供了断开连接的大陆节点,而不将它们分组。
Match (c:Country)
CALL apoc.create.vNode(['Continent'],{name:c.continent}) yield node as s
Return c, apoc.create.vRelationship(s,'HAS_COUNTRY',{},c), s
如何使用 cypher 进行查询以在特定节点上生成虚拟节点、关系和组?
I'm currently learning cypher but trying to figure out how to accomplish the following.
My data
I have a set of nodes in Neo4j that have properties. These properties are seldom used and so having actual nodes does not make much sense. My example below is a list of country nodes with a property of name and continent. We don't often use continent, but it's still there for informational purposes.
[
{
name: "Australia",
continent: "Oceania"
},
{
name: "Canada",
continent: "North America"
},
{
name: "New Zealand",
continent: "Oceania"
},
{
name: "United States",
continent: "North America"
}
]
What I want
What we're looking to generate is a virtual node + relationship for each continent so we can see which countries belong to which continents. So, one node per continent and one node per country with multiple relationships from a single continent to the countries within.
What I have
What I have so far is below - but it's just gives me disconnected continent nodes for each of the continent values it finds without grouping them.
Match (c:Country)
CALL apoc.create.vNode(['Continent'],{name:c.continent}) yield node as s
Return c, apoc.create.vRelationship(s,'HAS_COUNTRY',{},c), s
How can I query with cypher to generate virtual nodes and relationships and group on a specific node?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过您的查询,您每行生成一个大陆,因此生成 4 个大陆,这就是您看到断开连接的大陆的原因。
您需要将同一大陆的国家/地区分组在一起,并仅在大陆上为它们创建
With your query, you generate one continent per row and thus 4 of them, that's why you see disconnected continents.
You need to group countries of the same continent together and create on continent only for them