【问题标题】:Using `filter` lambda in gremlin with javascript在 gremlin 中使用 `filter` lambda 和 javascript
【发布时间】:2020-06-08 15:16:37
【问题描述】:

我正在将 OrientDb 与 JavaScript 一起使用,并且我尝试过使用startingWith、containing、endingWith、notContaining、notEndingWith、notStartingWith 谓词失败。也许是我这边的错误实现,但我还没有找到有关如何使用的文档。 我一直在寻找一种使用 lambdas 过滤以获得 sql like 行为的方法,但没有成功。我尝试使用 described in this answer 方法,但它不适用于 JavaScript。使用谓词时,答案是错误的。

我也试过了: What is the equivalent of the gremlin queries in gremlin javascript?

我当前的 JavaScript 代码:

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();
    }
})();

【问题讨论】:

    标签: javascript orientdb gremlin predicate


    【解决方案1】:

    你没有说你的错误是什么,但我认为你的 Gremlin 应该使用has() 而不是where()

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

    另请注意,TextP 直到 TinkerPop 3.4.0 才可用,因此您需要确保您的图表(在您的情况下为 OrientDB)至少支持此版本的 TinkerPop。

    【讨论】:

      猜你喜欢
      • 2018-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2019-04-29
      • 1970-01-01
      相关资源
      最近更新 更多