1
votes

In my graph product vertex can have a composed_of edge from another product vertex.

Now I am trying to exclude a vertex and its children with composed_of edge when selecting all vertex with label product.

initially i have the id of the vertex to be excluded, but i dont know how to exclude it and its children when selecting all the product vertex in one query.

Seed db:

//add product vertex
g.addV('product').property('id', 'product1').property('pk', 'product1');
g.addV('product').property('id', 'product2').property('pk', 'product2');
g.addV('product').property('id', 'product3').property('pk', 'product3');
g.addV('product').property('id', 'product4').property('pk', 'product4');
g.addV('product').property('id', 'product5').property('pk', 'product5');


//add composed_of edge
g.V('product1').addE('composed_of').to(g.V('product2'))
g.V('product1').addE('composed_of').to(g.V('product3'))

now i want to be able to select product4 and product5 by excluding product1 and its children with composed_of edge.

note: im sorry if this commands wont work with your gremlin console because i first started learning gremlin using cosmosDB.

1

1 Answers

1
votes

I think this is what you looking for:

g.V().hasLabel('product').where(
    __.not(coalesce(
         hasId('product1'), 
         __.in('composed_of').hasId('product1')
    ))
)