0

I am using OrientDb with JavaScript and I have tried with startingWith, containing, endingWith, notContaining, notEndingWith, notStartingWith predicates unsuccessfully. Maybe is a wrong implementation from my side but I have not found documentation about how to use. I've been looking for a way to filter with lambdas to get a sql like behavior but have not been successful. I tried to use the method described in this answer, but it is not working on JavaScript. When using the predicates the answer is an error.

I've tried that too: What is the equivalent of the gremlin queries in gremlin javascript?

My current JavaScript code:

import * as gremlin from 'gremlin';
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const TextPredicated = gremlin.process.TextP;
const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator('usr', 'pwd');
const remote = new DriverRemoteConnection(
    'ws://localhost:8182/gremlin', {
    authenticator,
    traversalSource: 'g'
});

remote.addListener('socketError', (error) => { console.log(`socketError: ${error}`); });

(async () => {
    try {
        remote.open();
        const g = await traversal().withRemote(remote);
        const results = await g.V()
            .where('username', TextPredicated.containing('john'))
            .toList();
        console.log(results);
        remote.close();
    } catch (error) {
        console.log(error);
    } finally {
        remote.close();
    }
})();
iLevi
  • 936
  • 4
  • 10
  • 26

1 Answers1

0

You don't say what your error is, but I think your Gremlin should use has() rather than where():

const results = await g.V()
        .has('username', TextPredicated.containing('john'))
        .toList();

Also note that TextP did not become available until TinkerPop 3.4.0 so you'd need to be sure that your graph (in your case, OrientDB) supports at least this version of TinkerPop.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135