从gremlin数据库中获取数据并在nodejs中迭代
Get data from gremlin database and iterate in nodejs
我是 gremlin 的新手。使用 nodejs 我连接了 gremlin 并添加了几个顶点。
假设我有 10 个不同的顶点并与边相连。有没有办法读取和迭代nodejs中的数据。它就像带有条件的简单 select 查询.. (select * 来自用户名='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);
}
假设您已将“用户名”添加为顶点上的 属性,并且“用户”是顶点上的标签,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。
我是 gremlin 的新手。使用 nodejs 我连接了 gremlin 并添加了几个顶点。
假设我有 10 个不同的顶点并与边相连。有没有办法读取和迭代nodejs中的数据。它就像带有条件的简单 select 查询.. (select * 来自用户名='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);
}
假设您已将“用户名”添加为顶点上的 属性,并且“用户”是顶点上的标签,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。