Join.js
function performJoining (sourceData, joinSet, joinArgs) {
        var length = joinSet.length,
            i,
            rightKeyAccessors = [];

        joinArgs.rightKeyPropertyPaths.forEach(function (keyValue) {
            rightKeyAccessors.push(getKeyValueAccessorFromKey(keyValue));
        });

        for (i = 0; i < length; i += 1) {
            var rightRecord = joinSet[i],
                currentBin = joinArgs.keyHashBin;

            if (isNullOrUndefined(rightRecord)) {
                continue;//move onto the next, can't join on records that don't exist
            }

            //for each entry in the join set add it to the source document at the correct index
            rightKeyAccessors.forEach(function (accessor) {
                currentBin = currentBin[accessor(rightRecord)];
            });

            currentBin.forEach(function (sourceDataIndex) {
                var theObject = sourceData[sourceDataIndex][joinArgs.newKey];

                if (isNullOrUndefined(theObject)) {//Handle adding multiple matches to the same sub document
                    sourceData[sourceDataIndex][joinArgs.newKey] = rightRecord;
                } else if (Array.isArray(theObject)) {
                    theObject.push(rightRecord);
                } else {
                    sourceData[sourceDataIndex][joinArgs.newKey] = [theObject, rightRecord];
                }
            });
        }
    }
function performJoining (sourceData, joinSet, joinArgs) {
        var length = joinSet.length,
            i,
            rightKeyAccessors = [];

        joinArgs.rightKeyPropertyPaths.forEach(function (keyValue) {
            rightKeyAccessors.push(getKeyValueAccessorFromKey(keyValue));
        });

        for (i = 0; i < length; i += 1) {
            var rightRecord = joinSet[i],
                currentBin = joinArgs.keyHashBin;

            if (isNullOrUndefined(rightRecord)) {
                continue;//move onto the next, can't join on records that don't exist
            }

            //for each entry in the join set add it to the source document at the correct index
            rightKeyAccessors.forEach(function (accessor) {
                currentBin = currentBin[accessor(rightRecord)];
            });

            currentBin.forEach(function (sourceDataIndex) {
                var theObject = sourceData[sourceDataIndex][joinArgs.newKey];

                if (isNullOrUndefined(theObject)) {//Handle adding multiple matches to the same sub document
                    sourceData[sourceDataIndex][joinArgs.newKey] = rightRecord;
                } else if (Array.isArray(theObject)) {
                    theObject.push(rightRecord);
                } else {
                    sourceData[sourceDataIndex][joinArgs.newKey] = [theObject, rightRecord];
                }
            });
        }
    }
function performJoining ( sourceData , joinSet , joinArgs ) { var length = joinSet . length , i , rightKeyAccessors = [ ] ; joinArgs . rightKeyPropertyPaths . forEach ( function ( keyValue ) { rightKeyAccessors . push ( getKeyValueAccessorFromKey ( keyValue ) ) ; } ) ; for ( i = 0 ; i < length ; i += 1 ) { var rightRecord = joinSet [ i ] , currentBin = joinArgs . keyHashBin ; if ( isNullOrUndefined ( rightRecord ) ) { continue ; //move onto the next, can't join on records that don't exist } //for each entry in the join set add it to the source document at the correct index rightKeyAccessors . forEach ( function ( accessor ) { currentBin = currentBin [ accessor ( rightRecord ) ] ; } ) ; currentBin . forEach ( function ( sourceDataIndex ) { var theObject = sourceData [ sourceDataIndex ] [ joinArgs . newKey ] ; if ( isNullOrUndefined ( theObject ) ) { //Handle adding multiple matches to the same sub document sourceData [ sourceDataIndex ] [ joinArgs . newKey ] = rightRecord ; } else if ( Array . isArray ( theObject ) ) { theObject . push ( rightRecord ) ; } else { sourceData [ sourceDataIndex ] [ joinArgs . newKey ] = [ theObject , rightRecord ] ; } } ) ; } }
Join the join set with the original query results at the new key.
@param sourceData The original result set
@param joinSet The results returned from the join query
@param joinArgs The arguments used to join the source to the join set
Join the join set with the original query results at the new key .