Cypher query creating new nodes instead of building relationship with existing nodes

ぐ巨炮叔叔 提交于 2020-07-10 10:24:21

问题


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)

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.

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

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


回答1:


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)


来源:https://stackoverflow.com/questions/62802772/cypher-query-creating-new-nodes-instead-of-building-relationship-with-existing-n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!