18

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?

2 Answers2

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=

Swazimodo
  • 1,147
  • 1
  • 15
  • 34
0

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

Abbas Cyclewala
  • 549
  • 3
  • 10