Naatan
Naatan

Reputation: 3474

Filtering outer collection by joined collection

I'm working with the following query:

        FOR book IN books
            FOR summary IN summaries
                FILTER book._key == summary._key
                FILTER summary.title !=""
            RETURN { book, summary }

The intend is that it returns me all books and their summaries, except those that are lacking a title.

I've tried multiple variations of the above, but in every case it seems it is only filtering the summaries, and doesn't affect the books returned. So I'll always end up with books that are lacking a summary.title in my results.

I can understand why this happens, I'm filtering the summaries, not the books. I can also think of convoluted solutions in order to achieve the results I want, but they all feel like overkill for what I imagine to be a common use-case.

So assuming I'm not completely off on assuming this is a common-use case that arangodb has a solution for, could someone explain to me what would be the idiomatic way of addressing it in arangodb?

Upvotes: 0

Views: 23

Answers (2)

Naatan
Naatan

Reputation: 3474

Turns out this IS working, I just wasn't accounting for collections who did not HAVE a title property at all. The solution was to also filter for title != null.

Upvotes: 0

eshirvana
eshirvana

Reputation: 24603

how about you try this :

FOR summary IN summaries
    FILTER summary.title != ""
    FOR book IN books
        FILTER book._key == summary._key
    RETURN { book, summary }

Upvotes: 0

Related Questions