前言
之前一直以爲在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~ =.=