通过 Javascript 应用程序与 Gremlin 数据库的简单连接
Simple connectivity to a Gremlin DB via a Javascript Appliaction
对于这样一个基本问题,我深表歉意,但我似乎无法弄清楚如何做到这一点,而且文档都非常具体。
我只是想使用 gremlin 连接到标准的 Gremlin DB (Cosmos)。它在服务器上运行良好,但是当我从浏览器连接时,出现此错误:
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
没什么特别复杂的,而且错误似乎很清楚。
代码如下:
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
var DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
this.Graph = Gremlin.structure.Graph;
var dc = new DriverRemoteConnection(this.gremlin_websocket,this.gremlin_config_options);
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
当我执行以下代码时,它完成时没有 Javascript 错误。
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
this.Graph = Gremlin.structure.Graph;
this.gremlin_websocket = new WebSocket('ws://test_db.gremlin.cosmos.azure.com:8182/')
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
但是,我需要传递身份验证和收集信息(目前在身份验证器对象中)。但是WebSocket好像不支持,Driver Remote Connection好像也没有原生走websocket。我该怎么办?
不幸的是,我认为 gremlin-javascript 在浏览器中效果不佳。我认为这是您 运行 遇到的问题。请注意,TINKERPOP-2143 and an associated pull request 已经存在一个问题,现在已经部分完成了很长时间,但尚未完成。
查看 gremlin-browser,基于版本 gremlin-js v3.5.2 和 isomorphic-ws v4.0.1 的浏览器 JavaScript Gremlin 语言变体。使用 Azure Cosmos DB Gremlin API 2022 :)
进行测试
对于这样一个基本问题,我深表歉意,但我似乎无法弄清楚如何做到这一点,而且文档都非常具体。
我只是想使用 gremlin 连接到标准的 Gremlin DB (Cosmos)。它在服务器上运行良好,但是当我从浏览器连接时,出现此错误:
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
没什么特别复杂的,而且错误似乎很清楚。
代码如下:
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
var DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
this.Graph = Gremlin.structure.Graph;
var dc = new DriverRemoteConnection(this.gremlin_websocket,this.gremlin_config_options);
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
当我执行以下代码时,它完成时没有 Javascript 错误。
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
this.Graph = Gremlin.structure.Graph;
this.gremlin_websocket = new WebSocket('ws://test_db.gremlin.cosmos.azure.com:8182/')
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
但是,我需要传递身份验证和收集信息(目前在身份验证器对象中)。但是WebSocket好像不支持,Driver Remote Connection好像也没有原生走websocket。我该怎么办?
不幸的是,我认为 gremlin-javascript 在浏览器中效果不佳。我认为这是您 运行 遇到的问题。请注意,TINKERPOP-2143 and an associated pull request 已经存在一个问题,现在已经部分完成了很长时间,但尚未完成。
查看 gremlin-browser,基于版本 gremlin-js v3.5.2 和 isomorphic-ws v4.0.1 的浏览器 JavaScript Gremlin 语言变体。使用 Azure Cosmos DB Gremlin API 2022 :)
进行测试