Join

Copied!
( source, detail )

Description

The Join function finds all index tuples from the source SetRef and uses the source's values to be retrieved from the detail index terms.

The run time of Join is dependent on the number of elements in the underlying set or page (it’s linear, or O(1)). For very large sets or pages, executing Join might result in a query timeout error.

To work around this, you may specify a larger query timeout via the driver that you are using.

Parameters

Argument Type Definition and Requirements

source

SetRef

The source SetRef for the join operation.

detail

IndexRef or Lambda function

The IndexRef to join with the source SetRef, or the Lambda function which determines how to complete the join operation.

Returns

The SetRef for the join operation.

Examples

The index form is useful when the documents in the source_set match the terms in an index. Join returns documents from an Index (specified by detail) that match the terms from source.

Copied!
client.query(
  q.(
    q.(
      q.(
        q.('spellbooks_by_owner'),
        q.(q.('characters'), '181388642114077184')
      ),
      q.('spells_by_spellbook'),
    )
  )
)
.then((ret) => console.log(ret))
{ data:
   [ (id=181388642046968320, collection=(id=spells, collection=(id=collections))),
     (id=181388642071085568, collection=(id=spells, collection=(id=collections))) ] }

The Lambda form requires the Lambda function to be pure. i.e. it may not make any reads or writes.

Copied!
client.query(
  q.(
    q.(
      q.(
        q.('spellbooks_by_owner'),
        q.(q.('characters'), '181388642114077184'),
      ),
      q.(
        'spellbook',
        q.(q.('spells_by_spellbook'), q.('spellbook')),
      )
    )
  )
)
.then((ret) => console.log(ret))
{ data:
   [ (id=181388642046968320, collection=(id=spells, collection=(id=collections))),
     (id=181388642071085568, collection=(id=spells, collection=(id=collections))) ] }

The events view of Join contains events for joined sets as the join filtered by when the join document was live in the source set.

Copied!
client.query(
  q.(
    q.(
      q.(
        q.(
          q.('spellbooks_by_owner'),
          q.(q.('characters'), '181388642114077184'),
        ),
        q.('spells_by_spellbook'),
      )
    )
  )
)
.then((ret) => console.log(ret))
{ data:
  [  { ts: 1527095186458101,
       action: 'add',
       document:
        (id=181388642046968320, collection=(id=spells, collection=(id=collections))) },
     { ts: 1527095186458101,
       action: 'add',
       document:
        (id=181388642071085568, collection=(id=spells, collection=(id=collections))) } ] }

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!