MATCH n RETURN n Neo4j returns this collection The heart of graph database

Match n return n neo4j returns this collection the

This preview shows page 35 - 38 out of 40 pages.

MATCH n RETURN n Neo4j returns this collection: The heart of graph database technologies lies in the relationships it can set up between nodes. So to continue this example, we’ll set up a “teaches” relationship between Professor and course. We’ll use the MATCH command to create the relationship, and this time we’ll use a UNIQUE clause, which prohibits a duplicate relationship between “CS779” and Professor Schudy. MATCH course:Course, professor:Professor WHERE course.name = 'CS779' AND professor.name = 'Robert Schudy' CREATE UNIQUE (course)­[r:TAUGHT_BY]­>(professor) RETURN r And add more relationships between the other courses and professors. MATCH (course:Course) WHERE course.name = 'CS669' SET course.description = 'Database Design and Implementation' RETURN course.name, course.description MATCH (course:Course) WHERE course.name = 'CS625' SET course.description = 'Business Data Communication and Networks' RETURN course.name, course.description MATCH (course:Course) WHERE course.name = 'CS783' SET course.description = 'Enterprise Architecture' RETURN course.name, course.description MATCH course:Course, professor:Professor WHERE course.name = 'CS779' AND professor.name = 'Robert Schudy' CREATE UNIQUE (professor)­[r:TEACHES]­>(course)
Image of page 35
3/5/2016 Module 6 36/40 RETURN r MATCH course:Course, professor:Professor WHERE course.name = 'CS669' AND professor.name = 'Robert Schudy' CREATE UNIQUE (professor)­[r:TEACHES]­>(course) RETURN r MATCH course:Course, professor:Professor WHERE course.name = 'CS669' AND professor.name = 'Warren Mansur' CREATE UNIQUE (professor)­[r:TEACHES]­>(course) RETURN r MATCH course:Course, professor:Professor WHERE course.name = 'CS783' AND professor.name = 'Robert Schudy' CREATE UNIQUE (professor)­[r:TEACHES]­>(course) RETURN r MATCH course:Course, professor:Professor WHERE course.name = 'CS669' AND professor.name = 'George Maiewski' CREATE UNIQUE (professor)­[r:TEACHES]­>(course) RETURN r MATCH course:Course, professor:Professor WHERE course.name = 'CS625' AND professor.name = 'Warren Mansur' CREATE UNIQUE (professor)­[r:TEACHES]­>(course) RETURN r Visually, our nodes and relationships will look like this: This graph was created on the () site. To locate a particular node, instead of using SELECTs and JOINs, Neo4j uses a system of “graph traversal”. A graph traversal starts at a node and follows the paths to get to another node or series of nodes. Traversing a node has a constant time cost, because the traversal looks at one node at a time, rather than looking at the entire data set. To see all the courses taught by Professor Schudy, we’ll use a MATCH command that follows the course­professor relationship.
Image of page 36
3/5/2016 Module 6 37/40 MATCH (course)­­(professor) WHERE professor.name='Robert Schudy' RETURN course.description Which would result in this table: And we could use the START command to start at a given node and follow the relationships for that node.
Image of page 37
Image of page 38

You've reached the end of your free preview.

Want to read all 40 pages?

  • Spring '19
  • Hadoop

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture