![](/img/trans.png)
[英]Gremlin get all incoming and outgoing vertex, including their edges and directions
[英]Gremlin remove all Vertex
我知道如何通過id刪除頂點,但我需要刪除多個頂點(清理數據庫)。
刪除1 v是這樣的:
ver = g.v(1)
g.removeVertex(ver)
在最近的Gremlin 2.3.0中,刪除所有頂點最好用以下方法完成:
g.V.remove()
更新:對於版本Gremlin 3.x,您將使用drop() :
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().drop().iterate()
gremlin> graph
==>tinkergraph[vertices:0 edges:0]
請注意, drop()
不會像remove()
那樣自動迭代Traversal
,因此您必須顯式調用iterate()
才能進行刪除。 本教程將詳細討論Gremlin控制台中的迭代。
此外,請考慮不同的圖形系統可能有自己的方法來更快速有效地刪除該系統中的所有數據。 例如,JanusGraph有這種方法:
JanusGraphFactory.drop(graph)
其中“graph”是您希望清除的JanusGraph
實例。
你可以試試
g.V.each{g.removeVertex(it)}
g.commit()
如果你正在使用Tinkerpop3(Titan 1.0.0),如前所述,命令是:
g.V().drop()
這僅適用於使用Gremlin交互式REPL界面的情況。 為什么? drop
返回必須被遍歷過返回迭代器被應用並自動將的Gremlin REPL接口迭代的迭代器。
如果(像我一樣)您正在使用Gremlin的HTTP或WebSocket接口,則必須顯式迭代返回的迭代器:
g.V().drop().iterate()
...提交交易。 在Titan中,事務是隱式打開的,但必須明確關閉 :
g.tx().commit()
你可以這樣做;
graph.shutdown();
TitanCleanup.clear(graph);
在TinkerPop3中:
drop() - step(filter / sideEffect)用於從圖中刪除元素和屬性(即刪除)。
g.V().drop()
在TinkerPop3中,使用Titan-1.0.0,
g.V().drop()
g.tx().commit() (commit the changes)
適合我。 你可以嘗試一下
public class JanusGraphCleanup {
@Deprecated
public static void clear(JanusGraph graph) throws BackendException {
JanusGraphFactory.drop(graph);
}
}
參考: https : //github.com/JanusGraph/janusgraph/blob/master/janusgraph-core/src/main/java/org/janusgraph/core/util/JanusGraphCleanup.java
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.