The ternary operator does not evaluate both options, try this:

RETURN true ? "ok" : FAIL()

The result will be ["ok"] and no error is raised (short-circuiting). The 
problem is rather that sub-queries are always executed:

RETURN true ? "ok" : (RETURN FAIL())

Above query will be aborted, because the sub-query RETURN FAIL() is run. In 
your query, the sub-query is FOR id IN object.ids RETURN DOCUMENT(
'otherColl', id), which causes the trouble.

The problem can be circumvented by adding the the condition to the 
sub-query as well:

FOR doc IN 1 OUTBOUND 'coll/start' edgeColl
LET type = PARSE_IDENTIFIER(doc).collection
LET content = type == 'A'
    ? MERGE(doc, { "some": "other field" })
    : MERGE(doc, { profiles: (
        FOR id IN (type == 'B'
            ? doc.ids
            : [] // returning an empty array here will make it skip the FOR 
loop altogether
        ) RETURN DOCUMENT('otherColl', id))
    })
RETURN { type, content }

For your particular query, you can actually use one of the alternative 
signatures of DOCUMENT() however:

FOR doc IN 1 OUTBOUND 'coll/start' edgeColl
LET type = PARSE_IDENTIFIER(doc).collection
LET content = type == 'A'
    ? MERGE(doc, { "some": "other field" })
    : MERGE(doc, { profiles: DOCUMENT('otherColl', doc.ids) })
RETURN { type, content }

DOCUMENT(collName, idArray) returns an empty result set in case of 
documents from collection A missing the ids attribute.

I understand that it would be convenient to not have sub-queries execute 
unconditionally, but there are probably technical reasons why it currently 
works this way.
I'll discuss this with the team nonetheless and let you know if something 
can / will be improved in a future version.

-- 
You received this message because you are subscribed to the Google Groups 
"ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to