2014-02-13 14 views
1

以下查詢:正確用法的CREATE UNIQUE和/或合併時,例如

MATCH (LOCALID0:Ship {ShipID: "12345", ShipName: "Phil's Yacht"}) 
CREATE UNIQUE (LOCALID0:Ship {ShipID: "12345", ShipName: "Phil's Yacht" }) - [LOCALID1:contains] - > (LOCALID2:container {ContainerID: "91812" }), 
(LOCALID0) - [LOCALID3:contains] - > (LOCALID4:container {ContainerID: "87132" }), 
(LOCALID0) - [LOCALID5:contains] - > (LOCALID6:container {ContainerID: "47490" }), 
(LOCALID0) - [LOCALID7:contains] - > (LOCALID8:container {ContainerID: "13157" }), 
(LOCALID0) - [LOCALID9:contains] - > (LOCALID10:container {ContainerID: "22676" }) 

提供了以下錯誤:

Exception in thread "main" Can't create `LOCALID0` with properties or labels here. It already exists in this context 

當我重用的Cypher支架ID的一個,所以我必須繼續重複使用它的屬性?問題是它沒有意識到LOCALID0:Ship {ShipID:「12345」,ShipName:「Phil's Yacht」}與LOCALID0是同一個節點嗎?

回答

2

不,你只是重新使用標識符:

MATCH (LOCALID0:Ship { ShipID: "12345", ShipName: "Phil's Yacht" }) 
CREATE UNIQUE 
(LOCALID0)-[LOCALID1:contains]- >(LOCALID2:container { ContainerID: "91812" }), 
(LOCALID0)-[LOCALID3:contains]- >(LOCALID4:container { ContainerID: "87132" }), 
(LOCALID0)-[LOCALID5:contains]- >(LOCALID6:container { ContainerID: "47490" }), 
(LOCALID0)-[LOCALID7:contains]- >(LOCALID8:container { ContainerID: "13157" }), 
(LOCALID0)-[LOCALID9:contains]- >(LOCALID10:container { ContainerID: "22676" }) 

這將創建提供了LOCALID0匹配容器模式,要不然也不會。

如果您正在尋找創建船+容器模式如果船舶未找到(和 只有一次創造這個模式),那麼你可以嘗試:

MERGE (LOCALID0:Ship { ShipID: "12345", ShipName: "Phil's Yacht" }) 
CREATE UNIQUE 
(LOCALID0)-[LOCALID1:contains]- >(LOCALID2:container { ContainerID: "91812" }), 
(LOCALID0)-[LOCALID3:contains]- >(LOCALID4:container { ContainerID: "87132" }), 
(LOCALID0)-[LOCALID5:contains]- >(LOCALID6:container { ContainerID: "47490" }), 
(LOCALID0)-[LOCALID7:contains]- >(LOCALID8:container { ContainerID: "13157" }), 
(LOCALID0)-[LOCALID9:contains]- >(LOCALID10:container { ContainerID: "22676" }) 
+0

盧安妮或許你還可以添加一個例子使用MERGE而不是CREATE UNQIUE作爲rels並解釋這兩種模式? –