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

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


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