问题描述
我是格雷姆林的新手。使用nodejs,我连接了gremlin,并添加了一些顶点。
假设我有10个不同的顶点并与边相连。有什么方法可以读取和迭代nodejs中的数据。就像是带有条件的simle 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。