How can I restore data from a previous result in the browser?

后端 未结 1 1055
自闭症患者
自闭症患者 2021-01-06 06:16

I have a query that I ran in the neo4j web browser:

MATCH p=(z)<-[*]-(a)-[:foo]->(b) WHERE b.value = \"bar\" return p

This returned

1条回答
  •  离开以前
    2021-01-06 06:20

    You could use apoc.load.json to do this. Note that this solution will not preserve the internal node ids. APOC is a procedure library that extends built-in Neo4j functionality.

    Given the JSON file

    {"graph": {
            "nodes": [
              {
                "id": "32496",
                "labels": [
                  "Person"
                ],
                "properties": {
                  "born": 1967,
                  "name": "Carrie-Anne Moss"
                }
              },
              {
                "id": "32505",
                "labels": [
                  "Movie"
                ],
                "properties": {
                  "tagline": "Evil has its winning ways",
                  "title": "The Devil's Advocate",
                  "released": 1997
                }
              },
              {
                "id": "32494",
                "labels": [
                  "Movie"
                ],
                "properties": {
                  "tagline": "Welcome to the Real World",
                  "title": "The Matrix",
                  "released": 1999
                }
              },
              {
                "id": "32495",
                "labels": [
                  "Person"
                ],
                "properties": {
                  "born": 1964,
                  "name": "Keanu Reeves"
                }
              }
            ],
            "relationships": [
              {
                "id": "83204",
                "type": "ACTED_IN",
                "startNode": "32495",
                "endNode": "32505",
                "properties": {
                  "role": "Kevin Lomax"
                }
              },
              {
                "id": "83183",
                "type": "ACTED_IN",
                "startNode": "32496",
                "endNode": "32494",
                "properties": {
                  "role": "Trinity"
                }
              },
              {
                "id": "83182",
                "type": "ACTED_IN",
                "startNode": "32495",
                "endNode": "32494",
                "properties": {
                  "role": "Neo"
                }
              }
            ]
          }
        }
      } 
    

    We can recreate the graph using this query:

    CALL apoc.load.json("https://dl.dropboxusercontent.com/u/67572426/small_movie_graph.json") YIELD value AS row
    WITH row, row.graph.nodes AS nodes
    UNWIND nodes AS node
    CALL apoc.create.node(node.labels, node.properties) YIELD node AS n
    SET n.id = node.id
    WITH row
    UNWIND row.graph.relationships AS rel
    MATCH (a) WHERE a.id = rel.startNode
    MATCH (b) WHERE b.id = rel.endNode
    CALL apoc.create.relationship(a, rel.type, rel.properties, b) YIELD rel AS r
    RETURN *
    

    0 讨论(0)
提交回复
热议问题