Search code examples
orientdb

OrientDB How to check the relationship between 2 node


I have some vertices of class 'Product' which can be 'viewed', or 'ordered' by class 'User'..

My problem is that I want to write SQL query or MATCH command to get all Product which is 'viewed' by specific user, but it hasn't been ordered by any user..

How to check the relationship 'ordered' doesn't exist between 'Product' and 'User' in MATCH command?

Eg:

ProductA <-viewed- UserA
ProductB <-viewed- UserA
ProductC <-viewed- UserA
ProductD <-viewed- UserA
ProductA <-ordered- UserA
ProductD <-viewed- UserB
ProductD <-ordered- UserB



Input: User A
Output: ProductB, ProductC

Thanks,


Solution

  • Try this:

    MATCH {CLASS:Product, AS:pdt, WHERE: (in().size() == 1 and inE().@class = "viewed" and in().name contains "UserA")} RETURN pdt.name
    

    this is the output:

    enter image description here

    UPDATE

    MATCH {CLASS:Product, AS:pdt, WHERE: (in("viewed").name contains 'UserA' and in("ordered").size()=0)} RETURN pdt.name
    

    Hope it helps.

    Regards