How to use two matching operators in a cypher request

I would like to combine two requests into one request, and I'm not sure what will happen if 2 matching statements are used in one cypher request.

Say I have a list of friends, and I would like to see a list of my friends with each of their uncles and siblings listed in the collection. Can I have two conformity statements that will do the job? eg.

match friends-[:childOf]->parents-[:brother]->uncles , friends-[:childOf]->parents<-[:childOf]-siblings return friends, collect(siblings), collect(uncles) 

However, if I make such a request, it always does not return any results.

+6
source share
2 answers

Since you have already selected parents in your first match class, you can do this as follows:

 match friends-[:childOf]->parents-[:brother]->uncles with friends, parents, uncles match parents<-[:childOf]-siblings return friends, collect(siblings), collect(uncles) 
+7
source

You might want to make some of these relationships optional. For example, if you find a sibling but you do not find uncles, this query will return null because it does not satisfy both matching parameters. If you make the final relationship optional, you do not have to completely satisfy both articles in order to return data. So:

 match friends-[:childOf]->parents-[?:brother]->uncles , friends-[:childOf]->parents<-[?:childOf]-siblings return friends, collect(siblings), collect(uncles) 
+1
source

Source: https://habr.com/ru/post/944641/


All Articles