属性名称是参数时如何查询属性值? [英] How to query property value when property name is a parameter?

查看:59
本文介绍了属性名称是参数时如何查询属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我们可以查询类似以下内容的属性值:

Typically we can query property value for something like:

Match (n:Product)
where n.name="iPhone X"
return n

但是,在我的情况下,我不知道应该匹配哪个属性,但是我只知道值,在这种情况下,属性名称成为一种变量.我想要这样的东西:

However, in my case, I don't know which property I should match, but I only know the value, in which case the property name becomes a kind of variable. I want something like this:

Match (n:Product)
    where n.{name}="iPhone X"
    return n

或具有关系变量r:

Match (n:Product)-[{r}]->(c:Color {name:'white'})

在这两种情况下,在我的应用程序中,我都事先了解了一些属性或关系 value ,而没有明确知道应与之匹配的属性.

In both cases, in my application I know some property or relationship value beforehand, without knowing specifically which property it should match against.

此查询是否基于Neo4j或spring-data-neo4j支持的属性或关系值?

Is this query based on property or relationship values supported in Neo4j or spring-data-neo4j?

推荐答案

在此示例中看看:

CREATE (:Node {name : 'Bruno'})-[r:REL_TYPE]->()

设置Neo4j浏览器参数:

Setting Neo4j Browser parameters:

:param {prop : 'name', rel_type : 'REL_TYPE'}

然后查询:

MATCH (n:Node) 
WHERE n[{prop}] = "Bruno"
RETURN n

结果:

╒════════════════╕
│"n"             │
╞════════════════╡
│{"name":"Bruno"}│
└────────────────┘

也就是说,您可以将属性名称用作WHERE子句中方括号内的键.

That is: you can use the property name as a key enclosed in square brackets in the WHERE clause.

一种通过动态关系类型查询的解决方法可以使用

An workaround to query by dynamic relationship types can be using the type() function, this way:

MATCH (:Node)-[r]->()
WHERE type(r) = {rel_type}
return r

这篇关于属性名称是参数时如何查询属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆