[英]Neo4j: optional relationship in cypher query?
我想我不太了解密碼查詢中的可選關系。
示例數據可在此處找到http://console.neo4j.org/?id=qnyvxb
My insitution-[:PERMISSION]->My institution document
Other insitution-[:PERMISSION]->Other institution document
Parent institution document-[:PERMISSION]->Parent institution document
My Institution-[:ATTACHED_TO]->Parent institution<-[:ATTACHED_TO]-[Other institution
Super user-[:MEMBER_OF]->My Institution
我需要獲取超級用戶可以訪問的文檔。 我使用過的查詢:
START member=node(7)
MATCH (member)-[m:MEMBER_OF]->()-[?:ATTACHED_TO*..5]->()-[p:PERMISSION]->(documents)
RETURN documents.name
但是它僅返回“家長機構文件”。 我弄錯了可選的關系概念嗎? 我應該使用兩個查詢嗎?
謝謝!
您不需要可選的關系來解決這一問題。 嘗試:
CYPHER 1.9 START member=node(7)
MATCH member-[:MEMBER_OF]->inst-[:ATTACHED_TO*0..5]-otherinst-[:PERMISSION]->doc
RETURN doc.name
注意0..5
因為這也包括在查找doc
時從成員中找到的第一個inst
。 我還要提到的是,通過刪除>
,我使附件和權限鏈接成為多向鏈接,因為給定的ATTACHED_TO
關系不會以任何特定順序鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.