簡體   English   中英

如何使用版本^ 3上的gremlin與CosmoDB圖形數據庫建立新連接

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

我試圖在節點js中創建一個新的gremlin客戶端,但我找不到任何文檔如何設置與URL和主鍵(在Azure CosmosDB中生成)的連接。

有關如何在版本<v3中執行此操作的示例,例如此處

有關新版本gremlin的文檔可以在新文檔中找到 ,但它沒有解釋如何將主鍵放入對象中(包也不是很清楚,我試圖填充“cert”和“pfx”無濟於事。

有誰知道如何使用node的gremlin包v ^ 3.0.0連接到我的azure CosmosDB gremlin API?

嘗試將帳戶密鑰添加到請求正文。 我猜測連接字符串的屬性。

"AccountKey"= "YourReallyLongKeyHereYourReallyLongKeyHereYourReallyLongKeyHere"

編輯

進一步研究后,您可能需要根據此文檔添加授權標頭。

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

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

我使用最新的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>", }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM