简体   繁体   English

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

[英]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.

相关问题 Cayley:如何使用Cayley-Gremlin代码将顶点和边插入图形中? - Cayley: How do insert vertices and edges into graph using Cayley-Gremlin code? IndexedDB - 新版本的数据库 - IndexedDB - new version of database 使用gremlin-javascript将完整图形序列化为GraphSON的最佳方法是什么? - What is the best way to serialise a full graph as GraphSON using gremlin-javascript? 如何使用Rails数据库中的数据创建d3图 - How to create d3 graph using data from Rails database 如何使用gremlin查询将json保存为顶点属性值 - How to save json as vertex properties values using gremlin query 如何使用 API(或另一个图的元素)的 output 创建新图? - How can I create a new graph using output of an API (or the elements of another graph)? 如何在不使用客户端缓存的情况下下载文件的新版本? - How to download new version of file without using the client cache? 如何使用书签在新选项卡中启动功能? - How can I start a function in a new tab using a bookmarklet? 如何使用 numChildren() 在新的 firebase 版本 9 中计算父级的子级数? - How to count the number of of children for a parent in the new firebase version 9 using numChildren()? 如何建立数据库连接 - How to make a database connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM