【问题标题】:Connect to OrientDB with the Gremlin javascript driver使用 Gremlin javascript 驱动程序连接到 OrientDB
【发布时间】:2018-06-21 14:33:11
【问题描述】:

我正在努力寻找一个使用当前 gremlin javascript 驱动程序和 OrientDB 的示例。我无法让它连接到 OrientDB(已经使用启用 tinkerpop 的版本)。

我的示例代码如下所示:

const gremlin = require("gremlin")
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection

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

g.V().toList().then(function(data) {
   console.log(data)
}).catch(function(err) {
   console.log(err)
})

有人有任何一起使用它们的经验吗?谢谢

【问题讨论】:

  • 你有什么问题?你能运行 OrientDB TP3 版中嵌入的 GremlinServer 吗?
  • 是的,我可以通过 gremlin 控制台连接到数据库,但不能通过 gremlin javascript 驱动程序。
  • 你有重现这个的要点吗?谢谢

标签: orientdb gremlin tinkerpop tinkerpop3


【解决方案1】:

如果你想通过 Gremlin 连接 OrientDB,试试这个:

Local -> gremlin> g = new OrientGraph("plocal:db_path/nomeDB")

In-Memory -> gremlin> g = new OrientGraph("memory:nomeDB")

Remote -> gremlin> g = new OrientGraph("remote:localhost/nomeDB")

希望对你有帮助

问候

【讨论】:

  • 谢谢米歇拉!我能够通过 gremlin 控制台连接到数据库,但是我无法让 gremlin javascript 驱动程序工作。 [npmjs.com/package/gremlin] 我用示例代码更新了我原来的问题。
  • 这不适用于 javascript。仅适用于控制台。
【解决方案2】:

我挖了一点。 Gremlin Javascript 驱动程序不支持 GraphSON3

https://github.com/jbmusso/gremlin-javascript/issues/109

将此添加到您的 server.yaml 序列化程序配置中以添加对 v2 的支持

- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.orientdb.io.OrientIoRegistry] }}  

那么它应该可以工作

【讨论】:

  • gremlin npm 包现在指向官方的 TinkerPop3 javascript 驱动程序(不推荐使用 jbnusso 的版本),它支持 GraphSON3。但是,我使用 v2 序列化程序进行了尝试,得到了相同的结果:Vertex { id: '#33:0', label: '', properties: undefined }
  • NPM 是否支持 GraphSON3 上的包?
  • 我在对 Gremlin Server 3.3.1 错误使用 gremlin javascript 3.2.9 时收到此错误错误:服务器错误(无请求信息):请求的 OpProcessor 无效 [null] (499)
  • 根据 git repo [github.com/apache/tinkerpop/tree/master/gremlin-javascript/src/…,它在 2 个月前获得了 GraphSON3 支持。但是,defaultMimeType 是 v2,因此您必须在启动新的 DriverRemoteConnection 时提供一个选项对象,或者用“application/vnd.gremlin-v3.0+json”覆盖 driver-remote-connection.js 中的 defaultMimeType 我猜。
  • 我已经使用 V3 mimeType const g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin', { mimeType : "application/ vnd.gremlin-v3.0+json" })) 即使顶点在服务器上,我仍然得到一个空数组作为响应。我避免使用 OrientDB 并使用 gremlin-server-classic.yaml
【解决方案3】:

试试这个:

import * as gremlin from 'gremlin';
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(<db username>, <db password>);
const traversal = gremlin.process.AnonymousTraversalSource.traversal;

const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin', {
      authenticator: authenticator
    }));

注意网址中的/gremlin,而不是/demodb。 要指向 demodb 或其他数据库,请修改 OrientDB 中 config 文件夹中的 demodb.properties 文件。

如果您愿意,可以创建另一个属性文件,只需记住在 gremlin-server.yaml 文件中指向它即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多