【问题标题】:Get data from gremlin database and iterate in nodejs从 gremlin 数据库中获取数据并在 nodejs 中迭代
【发布时间】:2020-12-11 22:37:11
【问题描述】:

我是小精灵的新手。使用 nodejs 我连接了 gremlin 并添加了一些顶点。

假设我有 10 个不同的顶点并与边相连。有什么方法可以读取和迭代nodejs中的数据。它就像带有条件的简单选择查询.. (select * from users where username='john')

 async get_vertices_by_props(input) {
        
        var graph_data = await this.get_vertex(input.label,input.property_name)
         // some code here.. 
     
    }

async get_vertex(label, property) {
        if (!label || !property || !value) {
            return error;
        }
        return await this.g.V().hasLabel(label);
    }

【问题讨论】:

    标签: node.js cassandra gremlin janusgraph gremlin-server


    【解决方案1】:

    假设您在顶点上添加了“用户名”作为属性,而“用户”是顶点上的标签,则与 SQL select * from users where username='john' 等效的 Gremlin 为 g.V().hasLabel('users').has('username','john').valueMap(true)

    在上面的查询中:

    V() 为您提供所有顶点。

    hasLabel('users') 是应用于顶点标签的过滤器。

    has('username','john') 是顶点属性的过滤条件。

    valueMap 是一个投影运算符,将为您提供顶点的 ID、标签和所有属性。

    既然您开始学习,我建议您阅读 https://kelvinlawrence.net/book/Gremlin-Graph-Guide.html 以初步了解 Gremlin。

    【讨论】:

    • 谢谢!有帮助!你有任何关于 nodejs+gremlin 的好的链接吗?
    • 另外,对于迭代,我们可以在 valueMap() 之后添加 toList()..
    猜你喜欢
    • 1970-01-01
    • 2013-12-23
    • 2021-10-15
    • 2020-07-14
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    相关资源
    最近更新 更多