Gremin mergeV() Upsert:知道是否添加了顶点(无副作用)

问题描述 投票:0回答:1

CosmosDB Graph :“upsert”查询模式中,有一个关于使用

fold()/coalesce()/unfold()
样式模式更新插入顶点并了解顶点是否已添加或获取的精彩讨论:

g.V().has('event','id','1').
  fold().
  coalesce(unfold().
           project('vertex','exists').
             by(identity()).
             by(constant(true)),
           addV('event').property('id','1').
           project('vertex','exists').
             by(identity()).
             by(constant(false)))

该帖子还更新了使用

mergeV()
的更高级模式。我想知道我们是否可以将上面的内容“翻译”为更高级的
mergeV()
模式?

非常感谢任何帮助/见解!

新的

mergeV()
模式似乎需要一个列表作为输入,所以我不确定如何从原始查询中映射它。

gremlin amazon-neptune
1个回答
0
投票

您可以使用

onMatch
onCreate
了解
mergeV
搜索期间发生了什么。这是一种在此基础上生成类似于问题中描述的结果的方法。

g.mergeV([T.id:'1']).
    option(Merge.onMatch,sideEffect(constant(true).store('found')).constant([:])).
    option(Merge.onCreate,sideEffect(constant(false).store('found')).constant([:])).
    project('id','status').
      by(id()).
      by(select('found').unfold())

由于 ID 为“1”的顶点确实存在,因此运行时,这就是查询返回的内容:

{'id': '1', 'status': True}
© www.soinside.com 2019 - 2024. All rights reserved.