mergeV/mergeE 的所有示例似乎都很不错,但如何将它们转换为 JavaScript 并不明显。 我到目前为止:
const { onCreate, onMatch } = gremlin.process.merge;
const { from_, to } = gremlin.process.direction;
this
.mergeE(to, tgt.id)
.option(onCreate, { created: now, updated: now })
.option(onMatch, { updated: now })
但是 mergeE 指令会生成错误。
我尝试过:
.mergeE([to, tgt.id])
效果:“无法根据提供的参数找到确切的方法:NeptuneGraphTraversal.mergeE(ArrayList)”.mergeE(to, tgt.id)
无法根据提供的参数找到确切的方法.mergeE({ [to.toString()]: tgt.id, [from_.toString()]: this.id })
Neptune 发生意外错误;显然我们不能在 js 中执行 [to]: tgt.id如果有人有 javascript/typescript 中 mergeE 的清晰示例,那将会有很大帮助。我是在 Amazon Neptune 上下文中专门询问的,但希望它对其他情况也有用。 更好的是有一个 mergeV 的并排示例,但可能有很多问题要问。
谢谢你
这是我相信您想要实现的目标的翻译示例:
const gremlin = require('gremlin');
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const direction = gremlin.process.direction
const t = gremlin.process.t
const { onCreate, onMatch } = gremlin.process.merge;
const g = traversal().withRemote(new DriverRemoteConnection('wss://<CLUSTER ENDPOINT>:8182/gremlin'));
g.
mergeE(new Map([[t.label,"Test"],
[direction.out,'1'],[direction.in,'2']])).
option(onCreate,new Map([["created",Date.now()]])).
option(onMatch,new Map([["updated",Date.now()]])).elementMap().toList().then(data => console.log(data))