Loading TOC...

MarkLogic Server 11.0 Product Documentation
ModifyPlan.prototype.existsJoin

ModifyPlan.prototype.existsJoin(
   rightPlan as String,
   [keys as ondef | ondef[]],
   [condition as xs.boolean]
) as ModifyPlan

Summary

This method is a filtering join that filters based on whether the join exists or not but doesn't add any columns.

It filters the left row set to the rows that have a join in the right row set.

Parameters
rightPlan The row set from the right view.
keys Equality condition(s) expressed using one or more calls to the function op.on. These conditions are used to compare the left and right rows.
condition A boolean expression used to compare the left and right rows. See Boolean Expression Functions for the list of functions used to build boolean expressions.

Usage Notes

Both keys and condition are used to specify the join condition. keys allows for a simplified syntax for equality join condition. While condition allows for inequality and complex join conditions. This method combines keys and condition using an AND operator such that:
      view
        .existsJoin(
          otherView, 
          op.on(view.col('column1'), otherView.col('column2')),
          op.ge(view.col('column3'), otherView.col('column4'))
        )
is the same as
      view
        .existsJoin(
          otherView,
          null,
          op.and(
            op.eq(view.col('column1'), otherView.col('column2')),
            op.ge(view.col('column3'), otherView.col('column4'))
          )
        )

existsJoin is a method of the following classes:

Example

// It filters out {'r1':1, 'k1':'a'} in p1 as value 'a' exists in column 'k2' of p2
const op = require('/MarkLogic/optic');

const p1 = op.fromLiterals([
    {'r1':1, 'k1':'a'},
    {'r1':2, 'k1':'b'}
  ]);
const p2 = op.fromLiterals([
    {'r2':3, 'k2':'a'},
    {'r2':4, 'k2':'c'}
  ]);
p1.existsJoin(p2, op.on('k1', 'k2')).result();
  

Example

'use strict';
 
const op = require('/MarkLogic/optic');

const fruits = op.fromLiterals([
    {"fruit" : "mango", "count" : 10},
    {"fruit" : "apple", "count" : 7},
    {"fruit" : "orange", "count" : 9}
  ]);
const orders = op.fromLiterals([
    {"flavor" : "apple", "cups" : 5},
    {"flavor" : "orange", "cups" : 14}
  ]);

fruits.existsJoin(
  orders,
  op.on(op.col('fruit'), op.col('flavor')),
  op.ge(op.col('count'), op.col('cups'))
)
.result()

/* 
  row with fruit of 'apple' will be returned without data from orders
*/
    

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.