简体   繁体   中英

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).

Examples are available how to do this in versions < v3, such as here .

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).

Does anyone know how I can connect to my azure CosmosDB gremlin API with node's gremlin package v^3.0.0?

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=

I have used the latest gremlin lib to connect to 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:

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>", }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM