Reputation: 6343
In Node, what is the correct way to execute Gremlin queries against a database?
My current attempt using the Official Node OrientDB Driver:
const { ODatabase } = require('orientjs');
const db = new ODatabase({...});
db.query('g.V()')
.then(console.log, console.error);
And I get:
OrientDB.RequestError:
Cannot find a command executor for the command request: sql.g.V()
DB name="mynevo"
at child.Operation.parseError
(.../orientjs/lib/transport/binary/protocol33/operation.js:864:13)
However, when I execute g.V()
in the web interface, it works perfectly.
Clearly the Node driver or the server assumes the query is supposed to be SQL. Is there a way to tell it to be Gremlin, or is there some other way?
Upvotes: 1
Views: 508
Reputation: 1584
The easiest and quickest way to execute a gremlin query against OrientDB is to use the REST API (port 2480, NOT binary port 2424). It is one call, I suggest trying it out first in postman.
[POST] http://:2480/command//gremlin
Then the request body can look like this:
{
"command": "g.V().has('name', 'marko')"
}
Pass the OrientDB credentials as basic auth
In NodeJS/JavaScript simply use superagent or a similar module to call the REST API. Then analyze the results which are returned as JSON.
See also: https://orientdb.com/docs/last/OrientDB-REST.html
Look under Command section
Upvotes: 0
Reputation: 1949
You should be able to execute gremlin command using
```
db.query('g.V()', {
language : "gremlin",
class : "com.orientechnologies.orient.graph.gremlin.OCommandGremlin"
}).then(function(res){
console.log(res);
})
```
Upvotes: 1