2016-02-04 61 views
0

我有一個需要遷移到Neo4j的mongo集合。爲此,我會將其導出爲CSV。然後,我將使用Cypher將結果CSV導入Neo4j。集合中的文檔具有一個包含數組內部對象的數組。看看上面的JSON:將數組從CSV導入到Neo4j的對象

"services" : [ 
      { 
       "max_id" : "646767779849326594", 
       "log" : [ 
        { 
         "date" : 1443024000, 
         "steps" : 6 
        }, 
        { 
         "date" : 1442512800, 
         "steps" : 1 
        } 
       ], 
       "service" : "home_timeline" 
      }, 
      { 
       "max_id" : 0.0, 
       "log" : [ 
        { 
         "date" : 1443024000, 
         "steps" : 4 
        }, 
        { 
         "date" : 1442512800, 
         "steps" : 1 
        } 
       ], 
       "service" : "user_timeline" 
      }, 
      { 
       "max_id" : 0.0, 
       "log" : [ 
        { 
         "date" : 1443024000, 
         "steps" : 6 
        }, 
        { 
         "date" : 1442512800, 
         "steps" : 1 
        } 
       ], 
       "service" : "mentions_timeline" 
      } 
     ] 

我怎樣才能將它導入到Neo4?我已經找到了導入數組的解決方案。但我沒有發現類似於我的問題。 CSV的標題應該如何? Cypher代碼應該如何獲得這些元素?

回答

1

您可以使用JSON作爲Cypher查詢的參數。有幾個這樣的示例herehere

隨着你的例子是這樣的:

WITH {json} AS data 
UNWIND data.services AS service 
// Insert data for each service. 
MERGE (s:Service { "service_name": service.service}) 
SET s.max_id = service.max_id 
FOREACH (log IN service.logs | CREATE (l:Log {date: log.date, steps: log.steps})<-[:LOGGED]-(s)) 

也有從MongoDB的文檔數據模型轉換數據的Neo4j,你可能會發現有用的屬性圖模型的工具:https://github.com/neo4j-contrib/neo4j_doc_manager

+0

謝謝,威廉!我會看看這個! –