简体   繁体   中英

Gremlin get all vertices that are not connected to me

I have a simple graph where a user can by a product(premium, normal).

g.addV('user').as('1')
.property(single, 'name', 'peter')
.addV('product').as('2').property(single, 'premium', false)
.addV('product').as('3').property(single, 'premium', true).property(single, 'order', 1)
.addV('product').as('3').property(single, 'premium', true).property(single, 'order', 2)
.addE('bought').from('1').to('2')

在此处输入图像描述

I stuck with the query where i need to display only premium products that are not bought by the user. Thanks in advance.

There are a few ways this query can be approached. One way is to find all the premium products that Peter already owns first and then find all the premium products that are not part of that set.

gremlin> g.V().has('name','peter').
......1>       out('bought').
......2>       has('premium',true).
......3>       fold().as('a').
......4>   V().hasLabel('product').
......5>       has('premium',true).where(without('a'))    

==>v[42310]
==>v[42313]           

EDITED to add a sort at the end

gremlin> g.V().has('name','peter').
......1>       out('bought').
......2>       has('premium',true).
......3>       fold().as('a').
......4>   V().hasLabel('product').
......5>       has('premium',true).where(without('a')).
......6>       order().
......7>         by('order')     

==>v[42310]
==>v[42313]    

   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM