简体   繁体   中英

Neo4j (cypher): How do I find all nodes with a specific relationship?

In a neo4j database with nodes, linked by the 'ARTICLE_OF' relationship, how do I find all nodes with this relationship? Direction doesn't matter.

I tried a possible solution from here , but it seems outdated. I swapped SOME_RELATIONSHIP with my ARTICLE_OF , but it didn't work.

start n=node(*)
match n-[:ARTICLE_OF]-()
return distinct n

When I run it I get the following error :

START is deprecated, use: `MATCH (n)` instead.
        (line 1, column 1 (offset: 0))
"start n=node(*)"
 ^

I tried swapping start with match , but that only resulted in more errors. Let me know if you want to see those as well, but I think someone with experience might immediately see what I'm doing wrong.

Since your question uses the neo4j-browser tag, I assume you are using the Neo4j Browser.

The Neo4j Browser has a quick way to display (up to 25) instances of a relationship type. In the Browser's left-hand sidebar, you'll see a Relationship Types section. If you click on one of the relationship types in that section, the Browser will execute a query to get the relationships of that type (limited to 25). You can adjust the query (eg, by increasing or removing the LIMIT ) as you wish.

Here is an example of a generated query:

MATCH p=()-[r:ARTICLE_OF]->() RETURN p LIMIT 25

NOTE: The r variable can be omitted, as it is never used.

I think I found an answer, but please provide a better solution if you find flaws

MATCH (n)-[r:ARTICLE_OF]->(k) RETURN n, r, k

Did the trick, I think

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM