Lets assume the following entities:
A 'user' has a 'blog' and the blog has 'entries'. A blog can have multiple users and an entry has three properties, user, blog and a string entry. I want to write a cypher query that returns all the entries for a particular blog and user. I have both the user node id and the blog id. I can use the user id to start the node but how can the blog id be used? I don't have access to anything else which is unique, hence the node id is being used.
start user=(1) match (user开发者_运维问答)->[:BLOG]-(blog)->[:ENTRY](entry) where entry.blog = blogId return entry
Recommendations would be appreciated.
You can also use parameters to pass in the blog and user-ids.
START user=({userId}), blog=({blogId}) MATCH user-[:BLOG]->blog-[:ENTRY]->entry RETURN entry
then execute the cypher query with a parameter-Map
that contains userId=1,blogId=2
.
If you have the blog-id you don't have to pass in the user. As you didn't specify a relationship between user and entry (like AUTHOR
) it would return all the entries of the blog, which is probably not what you want.
START user=({userId}), blog=({blogId}) MATCH blog-[:ENTRY]->entry<-[:AUTHOR]-user RETURN entry
At first your cypher query looks wrong, maybe other version than stable?
start user=(1) match (user)->[:BLOG]-(blog)->[:ENTRY](entry) where entry.blog = blogId return entry
If you have user id and blog id I think it you can try this out:
START user=(userId), blog=(blogId) MATCH user-[:BLOG]->blog-[:ENTRY]->entry RETURN entry
I think, in graph database using foreign key is unnecessary.
精彩评论