标签:Cypher name title Fundamentals Movie ACTED Finding Hanks MATCH
Cypher Fundamentals
Reading Data from Neo4j
- Introduction to Cypher
- Retrieving Nodes
- Finding Relationships
- Traversing Relationships
- Finding Emil
- Filtering Queries
- Finding Specific Actors
Writing Data to Neo4j
- Creating Nodes
- Creating a Node
- Creating Relationships
- Creating a Relationship
- Updating Properties
- Adding Properties to a Movie
- Merge Processing
- Adding or Updating a Movie
- Deleting Data
- Deleting Emil
QUIZ
Finding Relationships
VideoTranscriptFinding relationships
OUR GOAL
As a movie fanaticI would like to find movies for a particular actor
So that I can watch a movie this evening
In the previous lesson, we used the MATCH
clause to find the node in our database that represented Tom Hanks.
MATCH (p:Person {name: 'Tom Hanks'})
RETURN p
We can extend the pattern in the MATCH
clause to traverse through all relationships with a type of ACTED_IN to any node. Our domain model shows that the ACTED_IN relationship goes in an outgoing direction from the Person node so we can add the direction in our pattern. We often refer to this as a traversal.
MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->()
Our data model dictates that the node at the other end of that relationship will be Movie node, so we don’t necessarily need to specify the :Movie label in the node - instead we will use the variable m.
cypherMATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m)
RETURN m.title
This code returns the titles of all moves that Tom Hanks acted in.
If our graph had different labels, for example Television and Movie nodes this query would have returned all Television and Movie nodes that Tom Hanks acted in. That is, if we had multiple types of nodes at the end of the ACTED_IN relationships in our graph, we could make sure that we only return movies.
cypherMATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m:Movie)
RETURN m.title
Because our graph only has Movie nodes that have incoming ACTED_IN relationships, this query returns the exact same results as the previous query.
Check your understanding
1. Specifying the relationship direction
Say we wrote our query above differently and started with the Movie node. Use the dropdown below to select the correct direction for the query.
Once you have selected your option, click the Check Results query button to continue.
cypherMATCH (m:Movie)(p:Person)
RETURN m.title, p.name
2. Query using a pattern
Which MATCH
clauses will return the names of the directors of the movie, The Matrix?
-
MATCH (m:Movie {title: 'The Matrix'})<-[:DIRECTED]-(p:Person) RETURN p.name
MATCH (m:Movie {title: 'The Matrix'})--(p:Person) RETURN p.name
MATCH (m:Movie {title: 'The Matrix'})<-[:DIRECTED]-(p) RETURN p.name
MATCH (m:Movie {title: 'The Matrix'})--(p:Director) RETURN p.name
标签:Cypher,name,title,Fundamentals,Movie,ACTED,Finding,Hanks,MATCH 来源: https://www.cnblogs.com/z-cm/p/16221140.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。