Orientdb + nodejs + gremlin

Hi,

My goal is to use nodejs gremlin to connect to orientdb database

My docker-compose.yml file looks as follows

version: '3'
services:
  orientdb:
    image: orientdb:latest
    volumes:
      - ./data:/orientdb/databases
    environment:
      ORIENTDB_ROOT_PASSWORD: root
      ORIENTDB_NODE_NAME: root
    ports:
      - 2480:2480
      - 2424:2424
      - 8182:8182

My nodejs code looks as follows

const gremlin = require('gremlin');

const  execute = async () => {

    const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator('root', 'root');
    const client = new gremlin.driver.Client('ws://localhost:8182/gremlin', {traversalSource: 'g', authenticator: authenticator});

    const result1 = await
    client.submit('g.V(vid)', {vid: 1});
    const vertex = result1.first();

    const result2 = await
    client.submit('g.V().hasLabel(label).tail(n)', {label: 'person', n: 3});

// ResultSet is an iterable
    for (const vertex of result2) {
        console.log(vertex.id);
    }

}

execute()

When I run the code I get following result
events.js:173 throw er; // Unhandled 'error' event ^ Error: socket hang up at createHangUpError (_http_client.js:330:15) at Socket.socketOnEnd (_http_client.js:433:23) at Socket.emit (events.js:193:15) at endReadableNT (_stream_readable.js:1129:12) at process.internalTickCallback (internal/process/next_tick.js:72:19) Emitted 'error' event at: at Connection._handleError (C:\development\databases\gremlin\node\node_modules\gremlin\lib\driver\connection.js:216:10) at WebSocket._ws.on (C:\development\databases\gremlin\node\node_modules\gremlin\lib\driver\connection.js:129:40) at WebSocket.emit (events.js:188:13) at WebSocket.finalize (C:\development\databases\gremlin\node\node_modules\ws\lib\WebSocket.js:182:41) at ClientRequest._req.on (C:\development\databases\gremlin\node\node_modules\ws\lib\WebSocket.js:647:10) at ClientRequest.emit (events.js:188:13) at Socket.socketOnEnd (_http_client.js:433:9) at Socket.emit (events.js:193:15) at endReadableNT (_stream_readable.js:1129:12) at process.internalTickCallback (internal/process/next_tick.js:72:19)

My Questions are

  1. Is the latest docker image of orientdb has gremlin enabled in it?
  2. Is this the right way to connect to orientdb via node js code

I am aware of the orientdb specific nodejs driver, but I want to stick to generic one who I can connect to a different type of graph database.

I am pretty new to orientdb + tinkerpop (gremlin) world, so please feel free to point out the obvious gaps.

Cheers,
Rohit

You are using the wrong image. The orientdb:latest is not tinkerpop ready.
Use 3.0.28-tp3 instead.

Your code its fine, but its recomended to use traversal instead of client submit.

const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator('root', 'root');
const remote = new gremlin.driver.DriverRemoteConnection(
    'ws://localhost:8182/gremlin', {
    authenticator,
    traversalSource: 'g'
});
remote.addListener('socketError', (error) => { console.log(`socketError: ${error}`); });
try {
    remote.open();
    const g = await traversal().withRemote(remote);
    const results = g.V().toList();
} catch (e) {
    console.log(e);
}