What is the query to access the nodes in reverse to a relationship in neo4j
neo4j, nosql
Solution
You can match arrows either way:
`start n = node:comments(_id='c101') match n-[r:HAS_COMMENT] -> a return a;`
`start n = node:comments(_id='c101') match n<-[r:HAS_COMMENT] - a return a;`
Problem
I am using neo4j as my graph db. I am having some problem with the queries. Here is the scenario. I have an neo4j index = `users`. I have all the user `nodes` in `users` index. I have another index called "`comments`" Every comment is a node. And Every comment has a relationship "HAS_COMMENT" with user node. So I have, `user_node ->HAS_COMMENT-> comment_node` I can get all the comments of a user by this query. ``` $ start n = node:users(username='user1') match n-[r:HAS_COMMENT] -> a return a; ``` Now, I want to get in reverse direction. I have to get username from comment. This is I am trying but getting null result. ``` $ start n = node:comments(_id='c101') match n-[r:HAS_COMMENT] -> a return a; ``` c101 is my comment id(node id); and it is present in db. How can I do this?