Join.js
function buildQueriesFromHashBin (keyHashBin, rightKeys, level, valuePath, orQueries, inQueries) {
            var keys = Object.getOwnPropertyNames(keyHashBin),
                or;

            valuePath = valuePath || [];

            if (level === rightKeys.length) {
                or = {};
                rightKeys.forEach(function (key, i) {
                    inQueries[i].push(valuePath[i]);
                    or[key] = valuePath[i];
                });

                orQueries.push(or);
                //start returning
                //take the value path and begin making objects out of it
            } else {
                keys.forEach(function (key) {
                    if (key !== "$val") {
                        var newPath = valuePath.slice(),
                            value = keyHashBin[key].$val;

                        newPath.push(value);//now have a copied array
                        buildQueriesFromHashBin(keyHashBin[key], rightKeys, level + 1, newPath, orQueries, inQueries);
                    }
                });
            }
        }
function buildQueriesFromHashBin (keyHashBin, rightKeys, level, valuePath, orQueries, inQueries) {
            var keys = Object.getOwnPropertyNames(keyHashBin),
                or;

            valuePath = valuePath || [];

            if (level === rightKeys.length) {
                or = {};
                rightKeys.forEach(function (key, i) {
                    inQueries[i].push(valuePath[i]);
                    or[key] = valuePath[i];
                });

                orQueries.push(or);
                //start returning
                //take the value path and begin making objects out of it
            } else {
                keys.forEach(function (key) {
                    if (key !== "$val") {
                        var newPath = valuePath.slice(),
                            value = keyHashBin[key].$val;

                        newPath.push(value);//now have a copied array
                        buildQueriesFromHashBin(keyHashBin[key], rightKeys, level + 1, newPath, orQueries, inQueries);
                    }
                });
            }
        }
function buildQueriesFromHashBin ( keyHashBin , rightKeys , level , valuePath , orQueries , inQueries ) { var keys = Object . getOwnPropertyNames ( keyHashBin ) , or ; valuePath = valuePath || [ ] ; if ( level === rightKeys . length ) { or = { } ; rightKeys . forEach ( function ( key , i ) { inQueries [ i ] . push ( valuePath [ i ] ) ; or [ key ] = valuePath [ i ] ; } ) ; orQueries . push ( or ) ; //start returning //take the value path and begin making objects out of it } else { keys . forEach ( function ( key ) { if ( key !== "$val" ) { var newPath = valuePath . slice ( ) , value = keyHashBin [ key ] . $val ; newPath . push ( value ) ; //now have a copied array buildQueriesFromHashBin ( keyHashBin [ key ] , rightKeys , level + 1 , newPath , orQueries , inQueries ) ; } } ) ; } }
Build the in and or queries that will be used to query for the join documents.
@param keyHashBin The bin to use to retrieve the query vals from
@param rightKeys The keys which will exists in the join documents
@param level The current level of recursion which will correspond to the accessor and the index of the right key
@param valuePath The values that have been gathered so far. Ordinally corresponding to the right keys
@param orQueries The total list of $or queries generated
@param inQueries The total list of $in queries generated
Build the in and or queries that will be used to query for the join documents .