密码查询创建新节点,而不是与现有节点建立关系 [英] Cypher query creating new nodes instead of building relationship with existing nodes

查看:89
本文介绍了密码查询创建新节点,而不是与现有节点建立关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个查询可建立Men节点和People节点之间的关系:

I currently have a query that builds a relationship between Men nodes and People nodes:

MATCH (m:Mem)
UNWIND m.personID as person
MERGE (p:Person{personID:person})
MERGE (m)-[:WITH]->(p)

Mem节点包含要解散的PersonID数组,然后将它们与具有相应PersonID的Person节点匹配。但是,查询正在与其创建的 new 人员节点建立关系,而只具有相应的personIDs属性(而没有其他属性),而不是与 现有 具有相应personID的Person节点。

The Mem nodes contain an array of PersonIDs that I am unwinding and then matching to the Person nodes with the corresponding PersonIDs. However, the query is building the relationship with new Person nodes that it creates, with just the corresponding personIDs property (and no other properties) instead of building the relationship with the existing Person nodes with the corresponding personIDs.

即使我对具有ID的节点的personID属性具有唯一约束,也会发生这种情况人标签。

This is happening even though I have a unique constraint on the personID property for nodes with the Person label.

如何编写建立关系但不使用相应的personID创建新节点的查询?

How can I write a query that build the relationships but doesn't create new nodes with the corresponding personIDs?

推荐答案

由于现有节点将 personID 存储为整数,因此需要转换 person 通过 TOINTEGER()函数将字符串值转换为整数:

Since the existing nodes store personID as an integer, you need to convert the person string values to integers via the TOINTEGER() function:

MATCH (m:Mem)
UNWIND m.personID as person
MERGE (p:Person {personID: TOINTEGER(person)})
MERGE (m)-[:WITH]->(p)

这篇关于密码查询创建新节点,而不是与现有节点建立关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆