如何使用 Neptune + nodejs 中的值过滤属性



with Neptune + nodejs

g.V().hasLabel('A').properties()

返回:

id, label, value
1, 'p1','v1'
2, 'p1','b2'
3, 'p1','b3'
4, 'p1','d4'

如何执行筛选器,使其仅返回:

id, label, value
2, 'p1','b2'
3, 'p1','b3'

我试过了

g.V().hasLabel('Device').properties().value().is(containing('b'))

但它抛出错误不支持操作异常

我也试过g.V().hasLabel('Device').where(properties().value().is(containing('b')))

同样的错误,但我认为这是因为我在多个属性中有不同的数据类型,包含方法在遇到数字类型时失败.....

您可能不需要使用properties,除非您打算执行诸如删除属性之类的操作。您应该能够简单地执行以下操作:

g.V().hasLabel('Device').has('value',containing('b'))

我假设"价值"是您财产的名称。如果没有,请澄清。

已编辑以添加更多示例。

如果你想测试所有属性,你可以做这样的事情,找到匹配的属性。

gremlin> g.addV('test').property('x','Hello').
property('y','Another one').
addV('test').property('y','Goodbye')
==>v[12b93051-decf-3be5-85cd-cbc4c27e42f9]
g.V().hasLabel('test').
properties().hasValue(TextP.containing('ll'))
==>vp[x->Hello]

如果需要包含属性的顶点

gremlin> g.V().hasLabel('test').
where(properties().hasValue(TextP.containing('ll')))
==>v[14b93051-dece-db72-9f46-46df7513a14c]

您可以使用过滤器

g.V().hasLabel('Device').filter({ it.getProperty("value").startsWith("b") })

g.V().hasLabel('Device').filter({ it.getProperty("value").contains("b") })

编辑: 此查询适用于纯 Gremlin 而不是 Neptune 版本。

最新更新