Gremlin.createClient() 在版本 2.6.0 中工作,但在版本 3.3.4 中不起作用,我知道它从 3.3.4 开始已弃用。我想连接到服务器并执行查询。下面的代码是在2.6版本中执行。我想在 3.3.4 中执行相同的查询。
const Gremlin = require('gremlin');
const client = Gremlin.createClient(8182, 'localhost');
client.execute('g.V()', { }, (err, results) => {
if (err) {
return console.error(err)
}
console.log(results);
});
如何在 3.3.4 版本中写入?
最佳答案
如果可能的话,TinkerPop 不再建议使用脚本。最好用您选择的语言编写 Gremlin,对于您的情况是 Javascript:
const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
g.V().hasLabel('person').values('name').toList()
.then(names => console.log(names));
也就是说,您应该仍然可以通过这种方式提交脚本:
const gremlin = require('gremlin');
const client = new gremlin.driver.Client('ws://localhost:8182/gremlin', { traversalSource: 'g' });
const result1 = await client.submit('g.V(vid)', { vid: 1 });
const vertex = result1.first();
请查看完整reference documentation了解更多信息。
关于Gremlin.createClient 不是 3.3.4 版本中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56097422/