我正在寻找一个查询,该查询可以创建完整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字符串的图实例?
答案 0 :(得分: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服务器当前的工作目录中。