Cypher: return nodes that DO NOT have a certain relationship

1,597 views
Skip to first unread message

Matt MacKenzie

unread,
May 11, 2012, 2:44:17 PM5/11/12
to ne...@googlegroups.com
Hi,

So I have this:

@Query("start u=node({0}) match(u)-[:OWNS]-g return g")
 List<Group> findGroupsForUser( Long id );

It works great, it gives me Groups that are "owned" by a User.  

Can anyone suggest how I would flip this on its head, and list all Groups that are NOT owned by the given user?

Thanks :-)

-matt

Matt MacKenzie

unread,
May 11, 2012, 6:53:14 PM5/11/12
to <neo4j@googlegroups.com>
We figured this out if anyone needs it let me know. I still have SQL on he brain, hoping I learn cypher a bit faster than I am now :D

Matt MacKenzie

Duane Nickull

unread,
May 11, 2012, 7:17:55 PM5/11/12
to ne...@googlegroups.com
Please share ;-p

Where not(g.owner = UserID) doesn't work with iterators I think? How did
you manage?

Duane Nickull


***********************************
Consulting and Contracting; Proven Results!
i. Neo4J, Java, LiveCycle ES, Flex, AIR, CQ5 & Mobile
b. http://technoracle.blogspot.com
t. @duanechaos
"Don't fear the Graph! Embrace Neo4J"

Michael Hunger

unread,
May 11, 2012, 7:30:30 PM5/11/12
to ne...@googlegroups.com
Please always share whatever you learned, that's the only way OSS communities work.

Michael

Michael Hunger

unread,
May 11, 2012, 7:30:01 PM5/11/12
to ne...@googlegroups.com
you would have to get all groups and see that they don't have a relationship to the user.

so if you have an indexed property on group it is nice and readable
@Query("start u=node({0}),g=node:Group("id:*") where not (u-[:OWNS]->g) return g")
 List<Group> findGroupsNotForUser( Long id );

otherwise
@Query("start u=node({0}),g=node:__types__(className='com.uberity.model.Group') where not (u-[:OWNS]->g) return g")
 List<Group> findGroupsNotForUser( Long id );

Andres Taylor

unread,
May 12, 2012, 1:35:28 AM5/12/12
to ne...@googlegroups.com
Can you find the groups in any other way than getting to them through the users?

Andrés

Andres Taylor

unread,
May 12, 2012, 1:36:37 AM5/12/12
to ne...@googlegroups.com
On Sat, May 12, 2012 at 7:35 AM, Andres Taylor <andres...@neotechnology.com> wrote:
Can you find the groups in any other way than getting to them through the users?

Ignore me. Gmail hadn't loaded the rest of the thread yet.

Andrés 
Reply all
Reply to author
Forward
0 new messages