【问题标题】:How to parse json and create nodes with foreach in Neo4j?如何在 Neo4j 中解析 json 并使用 foreach 创建节点?
【发布时间】:2019-11-08 00:27:08
【问题描述】:

示例 json:

{
    "data": [
            {
                "file" : "1.txt",
                "type" : "text"
            },
            {
                "file" : "2.json",
                "type" : "json"
            },
            {
                "file" : "1.html",
                "type" : "html"
            }
    ]
}

我正在尝试使用文件和类型作为属性创建 3 个节点

我正在使用以下查询在 neo4j 中创建节点

WITH {json} AS document 
UNWIND document.data AS data
FOREACH (node in data| CREATE(m:`member`) SET m = node )

当我使用 py2neo 驱动程序时出现以下错误:

AttributeError: 'module' object has no attribute 'SyntaxError'

【问题讨论】:

    标签: neo4j cypher py2neo gql neo4j-apoc


    【解决方案1】:

    在你的情况下要么使用 UNWIND 或 FOREACH

    WITH {json} AS document 
    UNWIND document.data AS data
    CREATE(m:`member`) SET m = data
    

    WITH {json} AS document 
    FOREACH (node in document.data | CREATE(m:`member`) SET m = node )
    

    【讨论】:

      【解决方案2】:

      查询应该像 -

       WITH {json} AS document
       FOREACH (node in document.data| CREATE(m:`memeber`) SET m = node )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-26
        • 2014-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-26
        相关资源
        最近更新 更多