开发者

Cypher quering using a node Id

开发者 https://www.devze.com 2023-04-12 17:26 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消