[英]How to start a new connection with CosmoDB graph database using gremlin on version ^3
I am trying to create a new gremlin client in node js, but I cannot find any documentation how to set up the connection with both a URL and a primary key (as generated in Azure CosmosDB). 我试图在节点js中创建一个新的gremlin客户端,但我找不到任何文档如何设置与URL和主键(在Azure CosmosDB中生成)的连接。
Examples are available how to do this in versions < v3, such as here . 有关如何在版本<v3中执行此操作的示例,例如此处 。
Documentation on the new version of gremlin is available on the new documentation , but it does not explain how to put the primary key into the objects (the package is not very clear either, I've tried to populate "cert" and "pfx" to no avail). 有关新版本gremlin的文档可以在新文档中找到 ,但它没有解释如何将主键放入对象中(包也不是很清楚,我试图填充“cert”和“pfx”无济于事。
Does anyone know how I can connect to my azure CosmosDB gremlin API with node's gremlin package v^3.0.0? 有谁知道如何使用node的gremlin包v ^ 3.0.0连接到我的azure CosmosDB gremlin API?
Try adding an account key to the request body. 尝试将帐户密钥添加到请求正文。 I'm guessing by the properties of the connection string .
我猜测连接字符串的属性。
"AccountKey"= "YourReallyLongKeyHereYourReallyLongKeyHereYourReallyLongKeyHere"
Edit 编辑
After further research you might need to add an authorization header based on this documentation . 进一步研究后,您可能需要根据此文档添加授权标头。
type={typeoftoken}&ver={tokenversion}&sig={hashsignature}
Example: type=master&ver=1.0&sig=5mDuQBYA0kb70WDJoTUzSBMTG3owkC0/cEN4fqa18/s= 示例:type = master&ver = 1.0&sig = 5mDuQBYA0kb70WDJoTUzSBMTG3owkC0 / cEN4fqa18 / s =
I have used the latest gremlin lib to connect to cosmos db. 我使用最新的gremlin lib连接到cosmos db。 Here is my code:
这是我的代码:
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',
});
Then you can use the following for submitting a command to the server which returns a promise: 然后,您可以使用以下命令向服务器提交一个返回promise的命令:
query = 'g.V().count()';
client.submit(query).then(successfn,errorfn);
The config used is of the following format: 使用的配置格式如下:
{ "host": "<cosmosdbname>.gremlin.cosmosdb.azure.com", "password": "<secret-key>", "port": 443, "user": "/dbs/<dbname>/colls/<collectionName>", }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.