通过Javascript应用程序与Gremlin DB的简单连接
对于这样一个基本的问题,我深表歉意,但我似乎不知道该怎么做,而且文档都非常具体 我只是想用Gremlin连接到标准的gremlindb(Cosmos)。它在服务器上工作得很好,但当我从浏览器连接时,我会出现以下错误:通过Javascript应用程序与Gremlin DB的简单连接,javascript,node.js,azure-cosmosdb,gremlin,Javascript,Node.js,Azure Cosmosdb,Gremlin,对于这样一个基本的问题,我深表歉意,但我似乎不知道该怎么做,而且文档都非常具体 我只是想用Gremlin连接到标准的gremlindb(Cosmos)。它在服务器上工作得很好,但当我从浏览器连接时,我会出现以下错误: Error: ws does not work in the browser. Browser clients must use the native WebSocket object 没有什么特别复杂的,错误似乎很明显 代码如下: constructor() {
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);
};
但是,我需要传递身份验证和收集信息(当前在authenticator对象中)。但是WebSocket似乎不支持它,而且驱动程序远程连接似乎也不支持WebSocket。我该怎么办?不幸的是,我不认为gremlin javascript在浏览器中运行良好。我想这就是你遇到的问题。请注意,这方面已经存在一个问题,并且已经部分完成了很长一段时间,但尚未完成。感谢您的反馈!替代方案是什么:(抱歉,但我不知道解决办法。考虑一下未合并的分支可能是从评论中看到,人们已经成功地完成了这项工作。希望有人能尽快解决这个问题。哦,哇,那么人们一般不会从浏览器JavaScript连接到图形数据库吗?我还有其他的设计模式吗?”使用?我们在两个地方进行此对话-对于那些感兴趣的人,我的回答是:LOL,true:)我将转到线程并在完成后更新这里。