Search code examples
javaorientdb

Gremlinepipeline Edges between two Vertex


To check the edge between the vertex using Gremline pipeline in java code? I am able to create the edges but if we give the same vertex again the new edge will be created. I want to create a unique edge between the 2 vertex. Any help? I am using orientDB


Solution

  • You can create a unique index on the Edge class that will give you that constraint

    create class Foo extends V
    create class FooEdge extends E
    create property FooEdge.in LINK
    create property FooEdge.out LINK
    
    create index FooEdge_in_out on FooEdge (out,in) unique
    insert into Foo set name = 'Foo1'
    insert into Foo set name = 'Foo2'
    create edge FooEdge from (select from Foo where name = 'Foo1') to (select from Foo where name = 'Foo2')
    /* fail */
    create edge FooEdge from (select from Foo where name = 'Foo1') to (select from Foo where name = 'Foo2')