简体   繁体   English

如何从 JavaScript 中的 NEO4J 得到完整的图 JSON

[英]How to get complete graph as JSON from NEO4J in JavaScript

I see apoc.export.json.data but don't see complete working code example..我看到 apoc.export.json.data 但没有看到完整的工作代码示例。

I imagine the MATCH query would enable you to get any graph:我想 MATCH 查询将使您能够获得任何图表:

MATCH g=(someNode)-[someRel]-() return g
CALL apoc.export.json.data( g )

Then hopefully the APOC would return JSON of all the nodes and edges in the dataset resulting from the query.然后希望 APOC 将返回查询产生的数据集中所有节点和边的 JSON。 Expected JSON:预计 JSON:

{
  nodes:[
    { id:a1a1 , labels:[Something] , prop_a:99 },
    { id:a2a2 , labels:[Something] , prop_a:77 },
    { id:a3a3 , labels:[User] ,      prop_a:33 }
  ],
  edges:[
    { id:a1a1 , labels:[OWNS] , prop_a:99 },
    { id:a2a3 , labels:[OWNS] , prop_a:77 },
    { id:a4a5 , labels:[HAS] ,  prop_a:33 }
  ]
}

Instead of using an APOC, you can create your own output like below;除了使用 APOC,您还可以创建自己的 output,如下所示;

MATCH   g = ()-[]-()  
RETURN {nodes: collect(nodes(g)), 
        edges: collect(relationships(g))} as output

Sample result:示例结果:

{
  "nodes": [
    [
      {
        "identity": 10,
        "labels": [
          "Person"
        ],
        "properties": {
          "name": "Om Testing"
        }
      },
      {
        "identity": 11,
        "labels": [
          "Company"
        ],
        "properties": {
          "name": "ABC"
        }
      }
    ]
  ],
  "edges": [
    [
      {
        "identity": 8,
        "start": 10,
        "end": 11,
        "type": "WORKS",
        "properties": {
          "amount": 1000
        }
      }
    ]
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM