Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-06-2021 04:54 AM
Following cypher does not work, Can anyone please throw some light? thanks.
MATCH (u:`user`)
WHERE ID(u)=111
MATCH (u)<-[:`manager`]-(`subordinates`)-[:`manager`]->(`subordinates.manager`)
RETURN
`subordinates.manager`
this does not return anything, I am expecting it to return the user with id 111
following cypher works,
MATCH (u:`user`)
WHERE ID(u)=111
MATCH (u)<-[:`manager`]-(`subordinates`)
MATCH (`subordinates`)-[:`manager`]->(`subordinates.manager`)
RETURN
`subordinates.manager`
08-06-2021 05:29 AM
Hi,
Why aren't u just querying like:
MATCH (u:`user`)
WHERE ID(u)=111
RETURN u
In any case, using ID is not suggested.
Your query is trying to find 2 different persons managed by subordinates
tho.
H
08-08-2021 10:48 PM
Thanks for the reply. My question was around `
This path traversal does not go back to origin. I assume this is intentional by neo4j devs and wanted to know rationals behind this.
08-09-2021 04:35 AM
Hi Amit,
you have one user and you want to find all the subordinates (actually only one level below) and from those subordinates the managers (which means there is more than one manager for some subordinates) and you want to insure the given user is in the list of the managers.
In cypher, you will query like this:
MATCH (u:user)<-[:has_manager]-(s:subordinate)
WHERE ID(u)=111
with s
MATCH (s)-[:has_manager]->(m:manager)
RETURN m.name
Pay attention that user, manager and subordinate are labels. has_manager is a relationship type. You read the whole according to the arrow direction. Therefore I change the relationship from "manager" to a verb to have it like a sentence:
(some:subordinate)-[:has_manager]->(one:manager)
and
(one:manager)<-[:has_manager]-(some:subordinate)
are exactly the same.
All the sessions of the conference are now available online