将Gremlin CLI连接到远程TinkerPop Gremlin服务器

7

我正在使用 gremlin-javascript,通过以下代码连接到远程服务器:

const gremlin = require('gremlin')
const Graph = gremlin.structure.Graph
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection
const graph = new Graph()

const g = graph
  .traversal()
  .withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'))

通过gremlin命令行界面,我可以使用以下方式设置TinkerGraph

gremlin> graph = TinkerGraph.open()
gremlin> g = graph.traversal()

然而,我想连接到位于localhost:8182的图形数据库。但这并不完全行得通:

gremlin> graph = RemoteGraph.open('ws://localhost:8182/gremlin')

这还不太对:
gremlin> graph = TinkerGraph.open()
gremlin> g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'))

我该如何从命令行连接到这个服务器?
1个回答

13

Gremlin Console内置了对此的支持,并且在这里有详细描述。基本的连接命令是:

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182

在此时,您可以对远程图执行遍历操作:

gremlin> :> g.V().values('name')
==>marko
==>vadas
==>lop
==>josh
==>ripple
==>peter

如果您想取消使用:>语法,您可以将 REPL 设置为“控制台”模式,这样前缀就不再必要了:

gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[5ff68eac-5af9-4140-b3b8-d9311f30c053] - type ':remote console' to return to local mode

啊哈,我已经成功建立了远程连接,但是我的引用g的命令被反弹回来了。我需要进入控制台模式。再次感谢! - user479947

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接