使用nodejs gremlin创建不存在的顶点



我正在尝试使用这里描述的技术来防止gremlin中的重复边。我正在使用javascript,查询失败,并出现以下错误:Server error: Neither the map, sideEffects, nor path has a v-key: WhereEndStep(v) (500)。这正是我使用的查询:

import { process } from "gremlin";
const { statics } = process;
...
g
.V()
.has('user', 'id', this.id)
.fold()
.coalesce(statics.unfold(), statics
.addV('user')
.property('id', this.id))
.as('v')
.V()
.has('user', 'id', anotherUserId)
.fold()
.coalesce(statics.unfold(), statics
.addV('user')
.property('id', anotherUserId))
.coalesce(statics
.inE('follow')
.where(
statics.outV().as('v')
), statics.addE('follow').from_('v'))
.V()
.has('id', this.id)
.outE('skip')
.where(statics.inV().has('id', anotherUserId))
.drop()
.toList());

这是为了完整性,但查询永远不会到达最终的outE('skip'),它在最后一个coalesce失败,这是为了防止重复的边缘。请问我会错过什么?

正如有人在评论中指出的那样,问题是标签在.fold()中不持久。我的解决方案是分解查询,这样我就可以保留相关的标签。起作用的是:

import { process } from "gremlin";
const { statics } = process;
...
// first make sure the second user is available
g = g
.V()
.has('user', 'id', anotherUserId)
.fold()
.coalesce(statics.unfold(), statics
.addV('user')
.property('id', anotherUserId))
// then add the edge after making sure the first user is available
g
.V()
.has('user', 'id', this.id)
.fold()
.coalesce(statics.unfold(), statics
.addV('user')
.property('id', this.id))
.as('v')
.V()
.has('user', 'id', anotherUserId)
.coalesce(statics
.inE('follow')
.where(
statics.outV().as('v')
), statics.addE('follow').from_('v'))
.V()
.has('id', this.id)
.outE('skip')
.where(statics.inV().has('id', anotherUserId))
.drop()
.toList());

最新更新