Issues with while and where in match clause


Hi everyone,

I’ve built a litte social network based on some characters from the Simpsons.
There’s Lisa, Bart, Maggie, Homer, Marge and their grandparent Abe and Jackie. They are the nodes in the graph. The parent relationship is used for the edges. Marge and Homer are parents of Lisa, Bart and Maggie. Abe is the parent of Homer and Jackie the parent of Marge. So we get a little family tree.

Now I’m trying to search in this tree. I want to find out who Lisa’s grandparents are. So I’m matching Lisa and two traversals of the parent type in reverse direction or if you want so I’m looking for the parents of Lisa’s parents.

Works fine using this syntax:

MATCH {class:figure, as: lisa, where: (name= "Lisa Simpson")}
.in("parent"){class: figure}
.in("parent"){class: figure, as: person}

But now if I try with just one Edge definded and using the while condition to loop traversals I get:

MATCH {class:figure, as: lisa, where: (name= "Lisa Simpson")}
.in("parent"){class: figure, as: person, while: ($matched.depth < 2), where:(matched.depth != 0 AND $matched.depth != 1) }

If Lisa is at depth level 0 as initial node, her parents have to be at level 1 and her grandparents at level 2. It seems like the while condition works like a do while loop. I figured this out by quering Lisas parents using “$matched.depth < 1” and it still return Lisa and her parents. So $matched.depth < 2 should be fine.

In the where clause I have to write “matched.depth != 0 AND $matched.depth != 1” because it doesn’t return anything if I write “$matched.depth == 2” or “$matched.depth > 1” and I don’t get why.

Also returning the depth of each ancestor doesn’t work. It gets me a depth of 2 for all. Am I missing anything or what is this behaviour?

Thank you!



what version are you using?



I’m using the current Community Edition and the OrientDB Studio. That should be v 3.0.6.


With this:

traverse in("relationship") from(select expand(lisa) from(MATCH {class:User, as: lisa, where: (name= "Lisa")} RETURN lisa)) MAXDEPTH 2

you’re gonna have the parents and the ancestors of Lisa.

Hope it helps


I already found a way to solve the request but I want to understand why mine was not working. Why is the where condition not working with one simpler condition? Why do I need two conditions?

I’m writing my thesis about graph databases and this behavior ist not what I expected the database to do. So I want to understand why. The comfort working with each of the databases is also part of my topic.

There are also some more of those little things that I find confusing.

Thanks for your reply