OmG
OmG

Reputation: 18838

Connect to Cosmos Graph DB through NodeJs

I want to connect into the cosmos graph db in NodeJs. The implemented sample is coming from documentation. I've changed the example to connect into the emulator like the following:

var Gremlin = require("gremlin-secure");

const client = Gremlin.createClient(
    8081,
    "localhost", // or 127.0.0.1
    {
        "session": false,
        "ssl": false,
        "user": "/dbs/graphdb/colls/graphcollz",
        "password": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="  
    });

console.log('Running Drop');
client.on('error', (err) => {
     console.log(err.message);
});

I should mention that in the above documentation mentioned that:

The Gremlin endpoint must be only the host name without the protocol/port number, like mygraphdb.graphs.azure.com (not https://mygraphdb.graphs.azure.com or mygraphdb.graphs.azure.com:433).

Hence, the endpoint address for db is localhost without any protocol/port. Also, ssl is set to false to prevent "self signed certificate" error, and graphdb and graphcollz were created before in emulator.

In this way, I've gotten the following error when try to execute the following query:

client.execute('g.V().drop()', {}, (err, results) => {
     if (err) return console.error(err);
     console.log(results);
});

The error is:

read ECONNRESET

Also, Node js ECONNRESET post cannot help to solve the problem to connect into the emulator.

Now, the question is how can I connect into the cosmos graph db emulator through the NodeJS?

Upvotes: 0

Views: 550

Answers (1)

Michael Finger
Michael Finger

Reputation: 1120

The CosmosDB Emulator only emulates the DocumentDb endpoint. You can use the emulator with the .NET GraphDb SDK, but not the Node gremlin-secure module.

Here is the difference:

The .NET GraphDb SDK translates the Gremlin query to a DocumentDb query on the client side. It then calls the DocumentDb endpoint in Azure (your-site.documents.azure.com).

The Node GraphDb SDK sends the Gremlin query, as a string, to a GraphDB endpoint in Azure (your-site.graphs.azure.com). This endpoint appears to run code similar to the .NET SDK, but on the server side, translating the Gremlin query to a DocumentDb query.

Edit: Looks like Azure added a blurb on the emulator page that states they aren't currently supporting graphdb and tables. Nevertheless, I believe my answer is still correct: you could use the .NET GraphDB SDK and the emulator. (but the product is pre-release, so this may also be subject to change...):

enter image description here

Upvotes: 0

Related Questions