Thanks a lot for this very helpful answer!

Yes indeed, I would be interested to hear about other ways to achieve such 
heterogenous "feed" of documents. I may have to deal with more than 2 
source collections in the future, so using ternary operators for that will 
get cumbersome. Also, I'm open to use different edge collections for each 
of them if that can help.

Cheers,
Thomas

On Wednesday, July 6, 2016 at 7:58:20 PM UTC+2, Simran Brucherseifer wrote:
>
> 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