前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >gremlin-both()与bothE().bothV()的区别

gremlin-both()与bothE().bothV()的区别

作者头像
洋仔聊编程
发布2020-08-02 17:42:18
5050
发布2020-08-02 17:42:18
举报
前言

之前一直以为在gremlin查询中,gremlin的both()和bothE().bothV()效果相同。但是在实际应用中,发现他们并不是相同的。

let`s begin~ =.=

graph.V(3).both(): 返回 id为3的节点出边和入边获取到的目标节点,不包含id为3的源节点 graph.V(3).bothE().bothV():返回 id为3的节点的出边和入编获取到的所有节点,包含id为3的源节点

官网上解释

bothV() The bothV step returns the vertices at both ends of an edge

both() If we wanted to return vertices instead of edges, we could use the both step. This will return all of the vertices connected to the vertex with an ID of 3 regardless of whether they are connected by an outgoing or an incoming edge.

官网链接 http://kelvinlawrence.net/book/Gremlin-Graph-Guide.html#otherv

实际执行测试结果

ps:以下结果均在gremlin服务中实际测试,不过进行了信息脱敏处理

获取测试数据,执行:g.V().has("user_id","5796").bothE("edge_value")获取一条边如下,源节点(id为2539) 和 目标节点(id为8853)

==>e[2l8xqf8-15zryu8-5slx][2539-edge_value->8853]

使用both执行:g.V().has("user_id","5796").both("edge_value") 获取到一个节点,只包含目标节点,不包含源节点

==>v[8853]

使用bothE、bothV执行:g.V().has("user_id","5796").bothE("edge_value").bothV() 获取到两个节点,可以发现不仅包含目标节点还包含源节点

==>v[2539] ==>v[8853]

over~ =.=

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 官网上解释
  • 实际执行测试结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档