aj_blk
aj_blk

Reputation: 314

how to find ratings only to movie nodes in neo4j using cypher

CREATE (movie:Movie { title : 'The Matrix', year : '1999-03-31' })
CREATE (hotel:Hotel { name : 'Noushad Fried Chicken', acronym : 'NBC' })
CREATE (me:User { name: "Me" })
CREATE (me)-[:RATED { stars : 5, comment : "I love that movie!" }]->(movie);
CREATE (me)-[:RATED { stars : 3.5, comment : "food is great" }]->(hotel);

I want to find all the movies rated by me, but i when i try the following query

MATCH (me:User { name: "Me" }),(me)-[rating:RATED]->(movie) 
RETURN movie.title, rating.stars, rating.comment;

I get results including hotel ratings.

movie.title     rating.stars    rating.comment
The Matrix          5           I love that movie!
                    3.5         food is great

What is the query to get only the movie rating by me?

Upvotes: 0

Views: 465

Answers (1)

albertoperdomo
albertoperdomo

Reputation: 1949

If you want to restrict the ratings to movies you should specify the corresponding node label in the pattern:

MATCH (me:User { name: "Me" })-[rating:RATED]->(movie:Movie) 
RETURN movie.title, rating.stars, rating.comment;

Upvotes: 2

Related Questions