我試圖通過對apoc.load.json()的單個調用來UNWIND多個數組屬性。我擁有的版本並未完全正常工作:某些關係不會被加載。我的猜測是,這是由於通過WITH命令輸出管道。如果我對每個基於數組的屬性單獨運行展開,那麼我可以全部加載,但我很好奇它是如何一起完成的。UNWIND從JSON文件加載多個不相關的數組
任何見解和指針讚賞=)
//LOAD CLASSES AND UNWIND COMMON ITEMS,COMPANIONS,LOCATIONS
CALL apoc.load.json("file:///c://pathToFile//classes.json") YIELD value AS class
MERGE (c:Class {name: class.name})
SET
c.strength = class.strength,
c.intelligence = class.intelligence,
c.dexterity = class.dexterity,
WITH c, class.items AS items, class.companions AS companions, class.locations AS locations
UNWIND items AS item
UNWIND companions AS companion
UNWIND locations AS location
MERGE (i:Item {name: item})
MERGE (i)-[:LIKELY_HAS]->(c)
MERGE (c)-[:LIKELY_BELONGS_TO]->(i)
MERGE (comp:Class {name: companion})
MERGE (comp)-[:LIKELY_COMPANION_OF]->(c)
MERGE (c)-[:LIKELY_ACCOMPANIED_BY]->(comp)
MERGE (l:Location {name: location})
MERGE (l)-[:LIKELY_LOCATION_OF]->(c)
MERGE (c)-[:LIKELY_LOCATED_IN]->(l)
示例條目的JSON文件:
{
"name": "KNIGHT",
"strength": [75,100],
"intelligence": [40,80],
"dexterity": [40,85],
"items": [
"SWORD",
"SHIELD"
],
"companions":[
"KNIGHT",
"SERVANT",
"STEED"
],
"locations": [
"CASTLE",
"VILLAGE",
"CITY"
]
}
你能粘貼json文件的一些對象嗎? –
好點;完成=) – VeraKozya