如何在版本 ^3 上使用 gremlin 启动与 CosmoDB 图形数据库的新连接

How to start a new connection with CosmoDB graph database using gremlin on version ^3

提问人:Michal Paszkiewicz 提问时间:6/11/2018 更新时间:2/2/2023 访问量:605

问:

我正在尝试在 node js 中创建一个新的 gremlin 客户端,但我找不到任何文档如何使用 URL 和主键(在 Azure CosmosDB 中生成)设置连接。

在 v3 版本中提供了如何执行此操作<示例,例如此处

新文档中提供了有关版本 gremlin 的文档,但它没有解释如何将主键放入对象中(包也不是很清楚,我尝试填充“cert”和“pfx”但无济于事)。

有谁知道如何使用节点的 gremlin 包 v^3.0.0 连接到我的 azure CosmosDB gremlin API?

JavaScript 节点.js Azure-CosmosDB Gremlin

评论

0赞 Orel Eraki 10/12/2018
你能发表你尝试过什么吗?因为它看起来很简单。
1赞 Tomas Aschan 10/16/2018
@OrelEraki:我也没能弄清楚这一点(因此有赏金)。如果你认为这很简单,也许你可以在这个问题的答案中写一个样本?
0赞 Michal Paszkiewicz 10/16/2018
我写这个已经很久了,我不确定我能找到我写它的代码。
0赞 Michal Paszkiewicz 10/16/2018
@TomasAschan - 如果你能告诉我是否有任何答案适合你,我想我会把它作为接受的答案,因为上面有

答:

0赞 Swazimodo 10/13/2018 #1

尝试将帐户密钥添加到请求正文。我通过连接字符串的属性进行猜测。

"AccountKey"= "YourReallyLongKeyHereYourReallyLongKeyHereYourReallyLongKeyHere"

编辑

经过进一步研究,您可能需要根据此文档添加授权标头。

type={typeoftoken}&ver={tokenversion}&sig={hashsignature}  

例: type=master&ver=1.0&sig=5mDuQBYA0kb70WDJoTUzSBMTG3owkC0/cEN4fqa18/s=

0赞 Abbas Cyclewala 7/23/2019 #2

我使用最新的 gremlin lib 连接到 cosmos db。这是我的代码:

const authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(
  config.user,
  config.password
);
const endpoint = `wss://${config.host}:${config.port}/gremlin`;
const client = new Gremlin.driver.Client(endpoint, {
  authenticator,
  mimeType: 'application/vnd.gremlin-v2.0+json',
  rejectUnauthorized: true,
  traversalsource: 'g',
});

然后,您可以使用以下命令向服务器提交返回 promise 的命令:

query = 'g.V().count()';
client.submit(query).then(successfn,errorfn);

使用的配置采用以下格式:

{ "host": "<cosmosdbname>.gremlin.cosmosdb.azure.com", "password": "<secret-key>", "port": 443, "user": "/dbs/<dbname>/colls/<collectionName>", }