MarkLogic Server 11.0 Product Documentation
AccessPlan.prototype.joinDoc

AccessPlan.prototype.joinDoc(
   docCol as String,
   sourceCol as String
) as ModifyPlan

Summary

This function specifies a document column to add to the rows by reading the documents for an existing source column having a value of a document uri (which can be used to read other documents) or a fragment id (which can be used to read the source documents for rows).

As long as the values of the column are the same as document uris, the document join will work. If the document doesn't exist or the uri or fragment id is null in the row, the row is dropped from the rowset.

You should minimize the number of documents retrieved by filtering or limiting rows before joining documents.

Parameters
docCol The document column to add to the rows. This can be a string or column specifying the name of the new column that should have the document as its value.
sourceCol The document uri or fragment id value. This is either an op.fragmentIdCol object specifying a fragment id column or a document uri column. Joining on a fragment id is more efficient than joining on a uri column.

Usage Notes

joinDoc is a method of the following classes:

Example

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

op.fromLiterals([
	          {id:1, val: 2, uri:'/employee1.json'},
	          {id:2, val: 4, uri:'/employee2.json'},
	          {id:3, val: 3, uri:'/employee3.json'},
	          {id:3, val: 6, uri:'/employee20.json'}
	          ])
    .orderBy('id')
    .joinDoc(op.col('doc'), op.col('uri'))
    .result();
  

Example

// Returns the 'employee' and 'expense' source documents after the row data.

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

const employees = op.fromView('main', 'employees', null, 'DocId');
const expenses = op.fromView('main', 'expenses', null, 'DocId2');

const Plan =
   employees.joinInner(expenses, op.on(employees.col('EmployeeID'),
                       expenses.col('EmployeeID')))
  .joinDoc('Employee', op.fragmentIdCol('DocId'))
  .joinDoc('Expenses', op.fragmentIdCol('DocId2'))
  .select([employees.col('EmployeeID'), 'FirstName', 'LastName',
           expenses.col('Category'), 'Amount',
           'Employee', 'Expenses'])
  .orderBy(employees.col('EmployeeID'))
Plan.result();


  

Example

// Returns the 'employee' and 'expense' source documents after the row data.

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

const employees = op.fromView('main', 'employees', null, 'DocId');
const expenses = op.fromView('main', 'expenses', null, 'DocId2');

const Plan =
employees.joinInner(expenses, op.on(employees.col('EmployeeID'),
                                    expenses.col('EmployeeID')))
  .joinDocUri(op.col('employeeURI'), op.fragmentIdCol('docId'))
  .joinDocUri(op.col('expensesURI'), op.fragmentIdCol('docId2'))
  .joinDoc('Employee', op.col('employeeURI'))
  .joinDoc('Expenses', op.col('expensesURI'))
  .select([employees.col('EmployeeID'), 'FirstName', 'LastName',
           expenses.col('Category'), 'Amount',
           'Employee', 'Expenses'])
Plan.result();


  
Powered by MarkLogic Server | Terms of Use | Privacy Policy