Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-06-2020 10:46 AM
Hello 🙂
I'm trying to get Project nodes and their status, type, department and tag.
This is my query:
MATCH (p:Project)
MATCH (p)-[IS_STATUS]->(status:ProjectStatus)
MATCH (p)-[MEMBER_OF]->(type:Group)-[IS_TAG]->(GroupTag {slug:"type"})
MATCH (p)-[MEMBER_OF]->(dept:Group)-[IS_TAG]->(GroupTag {slug:"department"})
MATCH (p)-[MEMBER_OF]->(tag:Group)-[IS_TAG]->(GroupTag {slug:"tag"})
RETURN p, status, type, dept, tag
Is this query valid or am I misunderstanding something with Cypher ? Because it returns nothing, but I do get projects returned if I remove two of the three last MATCH, any of them.
Does my problem makes sense?
Thanks 🙂
Solved! Go to Solution.
08-24-2020 09:57 PM
First, make sure your relationship types are prefixed by :
, so for example, :MEMBER_OF
. If the :
is missing, then it's treated as a variable for the relationship, and the relationship will match on any rel type.
Likewise the last nodes should be :GroupTag
for their label, otherwise it will treat GroupTag
as a variable to match to any node.
And more importantly, when you reuse variables across your query, it means that the entity must be the same. This is also why your Cypher isn't returning any results. You are declaring that the GroupTag
node must be the same node across those match patterns, but must have differing slug properties. This is impossible, as a single node cannot have multiple values for a specific property.
So do not confuse labels/types with variables, if it's a label or type it must be prefixed with :
, otherwise your query will not do what you want it to do, and you'll get incorrect results.
08-06-2020 08:06 PM
One thing to keep in mind in your additional matches, it functions like a SQL inner join
would. If there aren't relationships to support all the conditions you're matching on, it's not going to return any data. If you want an equivalent Left Join
you can use an optional match
clause.
08-07-2020 12:53 AM
Kindly provide your data model and exact requirement
08-24-2020 09:57 PM
First, make sure your relationship types are prefixed by :
, so for example, :MEMBER_OF
. If the :
is missing, then it's treated as a variable for the relationship, and the relationship will match on any rel type.
Likewise the last nodes should be :GroupTag
for their label, otherwise it will treat GroupTag
as a variable to match to any node.
And more importantly, when you reuse variables across your query, it means that the entity must be the same. This is also why your Cypher isn't returning any results. You are declaring that the GroupTag
node must be the same node across those match patterns, but must have differing slug properties. This is impossible, as a single node cannot have multiple values for a specific property.
So do not confuse labels/types with variables, if it's a label or type it must be prefixed with :
, otherwise your query will not do what you want it to do, and you'll get incorrect results.
10-08-2020 03:23 AM
Thanks a lot !
Sorry for the late reply, I got sucked into urgent tasks and forgot to comment. The non-prefixed relationships tip did help A LOT, I was making that mistake in all my queries.
All the sessions of the conference are now available online