Neo4j cypher创建节点问题

时间:2018-01-09 19:04:09

标签: neo4j cypher

以下是Cypher查询

WITH [{commitID:'InvestmentProject',toolName:'GIT',projectId:'InvestmentProject1',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544},{commitID:'InvestmentProject',toolName:'JIRA',projectId:'InvestmentProject2',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544},{commitID:'RetailProject',toolName:'GIT',projectId:'RetailProject1',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544}] AS props  
UNWIND props AS event
MATCH (m:METADATA:DATATAGGING)
WHERE m.inputValue = event.projectId WITH m,props 
UNWIND props AS properties
CREATE (n:TESTDATATAGGING)
SET n=properties,n.level_1=m.level_1,n.level_2=m.level_2,n.level_3=m.level_3,n.level_4=m.level_4 return n

这创建了9个节点而不是3个

UNWIND props AS event
MATCH (m:METADATA:DATATAGGING)
WHERE m.inputValue = event.projectId
WITH m -----> returns 3 nodes

我做错了什么?

1 个答案:

答案 0 :(得分:1)

如果您只想创建3个TESTDATATAGGING个节点,那么您的查询不应再次UNWIND props {这将导致9次创建,因为每个m第一个MATCH中的1}行将在第二个UNWIND之后变为3行。

相反,您应该只重用event,如下所示:

WITH [{commitID:'InvestmentProject',toolName:'GIT',projectId:'InvestmentProject1',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544},{commitID:'InvestmentProject',toolName:'JIRA',projectId:'InvestmentProject2',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544},{commitID:'RetailProject',toolName:'GIT',projectId:'RetailProject1',vector:'DEVELOPMENT',committer:'XYZ developer',updaterValue:'Some random filed may be commitid',creationDate:1515496950544}] AS props  
UNWIND props AS event
MATCH (m:METADATA:DATATAGGING)
WHERE m.inputValue = event.projectId
CREATE (n:TESTDATATAGGING)
SET n=event,n.level_1=m.level_1,n.level_2=m.level_2,n.level_3=m.level_3,n.level_4=m.level_4
RETURN n;