简体   繁体   中英

ArangoDB: Traversal condition on related document

Been stuck for days with this concern, trying to accomplish this: See the provided picture. The black is the start vertex. Trying to get:

1: All child parts OUTBOUND (from) the start vertex

2: Condition: The children MUST have the INBOUND edge"types" and the other end a document with a variable set to "true" and of the type "type".

3: When a document of type "part" fails to met up the requirements with INBOUND document of type "type" with a attribute to "true", it stops the expand for that path then and there.

4: The documents who failed isn't included in the result either.

5: Should be compatible with any depths.

6: No subqueries (if possible without).

Example of graph

With the given information, the data model seems questionable. Why are there true and false vertices instead of a boolean edge attribute per partScrew ? Is there a reason why it is modeled like this?

Using this data model, I don't see how this would be possible without subqueries. The traversal down a path can be stopped early with PRUNE , but that does not support subqueries. That only leaves FILTER for post-filtering as option, but be careful, you need to check all vertices on the path and not just the emitted vertex whether it has an inbound false type.

Not sure if it works as expected in all cases, but here is what I came up with and the query result, which looks good to me:

LET startScrew = FIRST(FOR doc IN screw LIMIT 1 RETURN doc) // Screw A
FOR v,e,p IN 1..2 OUTBOUND startScrew partScrew
  FILTER (
    FOR v_id IN SHIFT(p.vertices[*]._id) // ignore start vertex
      FOR v2 IN 1..1 INBOUND v_id types
      RETURN v2.value
  ) NONE == false
  RETURN {
    path: CONCAT_SEPARATOR(" -- ", p.vertices[*].value)
  }

注释图

path
Screw A -- Part D
Screw A -- Part E
Screw A -- Part E -- Part F

Dump with test data: https://gist.github.com/Simran-B/6bd9b154d1d1e2e74638caceff42c44f

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