Reputation: 10561
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
or with relationship variable r:
Match (n:Product)-[{r}]->(c:Color {name:'white'})
In both cases, in my application I know some property or relationship value beforehand, without knowing specifically which property it should match against.
Is this query based on property or relationship values supported in Neo4j or spring-data-neo4j?
Upvotes: 4
Views: 1079
Reputation: 16373
Take a look in this example:
CREATE (:Node {name : 'Bruno'})-[r:REL_TYPE]->()
Setting Neo4j Browser parameters:
:param {prop : 'name', rel_type : 'REL_TYPE'}
Then querying:
MATCH (n:Node)
WHERE n[{prop}] = "Bruno"
RETURN n
The result:
╒════════════════╕
│"n" │
╞════════════════╡
│{"name":"Bruno"}│
└────────────────┘
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
Upvotes: 1