Connect to Cosmos Graph DB through NodeJs

429
July 05, 2017, at 04:31 AM

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?

Answer 1

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

Rent Charter Buses Company
READ ALSO
How to update the Node.js in windows

How to update the Node.js in windows

After I upgraded the ionic CLI, I have error when I do a ionic serve

397
ES7 - how can I replace Promise with await?

ES7 - how can I replace Promise with await?

One thing puts me off with Promise is that it is difficult to grasp with resolve and rejectAlso the need of wrapping for Promise is ugly

387
NodeJS EventEmitter on function

NodeJS EventEmitter on function

ive got a problemI am writing a node-steam-account handler to learn more about node

347
where's the nodeJS root on Windows? (sorry)

where's the nodeJS root on Windows? (sorry)

Here is my NodeJS code (trying to consolelog to a file):

323