【问题标题】:What is the best way to serialise a full graph as GraphSON using gremlin-javascript?使用 gremlin-javascript 将完整图序列化为 GraphSON 的最佳方法是什么?
【发布时间】:2019-08-31 13:07:44
【问题描述】:

我正在寻找可以创建完整 TinkerGraph 图的 GraphSON 序列化的单个查询。

// setup

const gremlin = require('gremlin')

const connection = new gremlin.driver.DriverRemoteConnection('ws://localhost:8182/gremlin')

const g = (new gremlin.structure.Graph()).traversal().withRemote(connection)

我能够将顶点、边和属性分别序列化为 GraphSON。以下语句仅创建所有顶点的 GraphSON 序列化。边可以用E()查询,属性用V().properties()查询。

// placed within an async function

const writer = new gremlin.structure.io.GraphSONWriter()

const serialisedVertices = writer.write(await g.V().toList())

是否有一个 gremlin-javascript 方法可以在一个步骤中将所有顶点、边和属性一起(而不是像上面那样单独)序列化为 GraphSON 字符串?

此外,如果一个完整的图可以序列化为单个 GraphSON 字符串,是否还有一个匹配的调用可以从 GraphSON 字符串中重新水合一个图实例?

【问题讨论】:

  • 您可以访问服务器吗?您使用的是哪个图形服务器?
  • 感谢您的回复 - 我正在使用带有 TinkerGraph 的 gremlin 服务器,它在可通过上面的 localhost 连接字符串访问的虚拟机上运行。为了清楚起见,我已经编辑了问题

标签: javascript gremlin tinkerpop tinkerpop3 gremlin-server


【解决方案1】:

启动 gremlin 3.4.x 可以使用io 步骤:

g.io("graph.json").read().iterate()
g.io("graph.json").write().iterate()

这些命令以graphson格式读取/写入完整的图形数据,这是一个json文件。如tinkerpop documentation中所写,还有更多受支持的格式

如果你运行的是 gremlin 3.3.x,你可以使用following command:

graph.io(graphson()).writeGraph("graph.json");

请注意,该文件存储在 gremlin 服务器当前工作目录中。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2010-11-06
  • 2010-09-10
  • 2012-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多