提问人:Michal Paszkiewicz 提问时间:6/11/2018 更新时间:2/2/2023 访问量:605
如何在版本 ^3 上使用 gremlin 启动与 CosmoDB 图形数据库的新连接
How to start a new connection with CosmoDB graph database using gremlin on version ^3
问:
我正在尝试在 node js 中创建一个新的 gremlin 客户端,但我找不到任何文档如何使用 URL 和主键(在 Azure CosmosDB 中生成)设置连接。
在 v3 版本中提供了如何执行此操作<示例,例如此处。
新文档中提供了有关新版本 gremlin 的文档,但它没有解释如何将主键放入对象中(包也不是很清楚,我尝试填充“cert”和“pfx”但无济于事)。
有谁知道如何使用节点的 gremlin 包 v^3.0.0 连接到我的 azure CosmosDB gremlin API?
答:
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>",
}
评论