Join.js
function runSubqueries (subQueries, callback, collection) {
        var i,
            responsesReceived = 0,
            length = subQueries.length,
            joinedSet = [];//The array where the results are going to get stuffed

        if (subQueries.length > 0) {
            for (i = 0; i < subQueries.length; i += 1) {

                collection.aggregate(subQueries[i], function (err, results) {
                    joinedSet = joinedSet.concat(results);
                    responsesReceived += 1;

                    if (responsesReceived === length) {
                        callback(joinedSet);
                    }
                });
            }
        } else {
            callback([]);
        }

        return joinedSet;
    }
function runSubqueries (subQueries, callback, collection) {
        var i,
            responsesReceived = 0,
            length = subQueries.length,
            joinedSet = [];//The array where the results are going to get stuffed

        if (subQueries.length > 0) {
            for (i = 0; i < subQueries.length; i += 1) {

                collection.aggregate(subQueries[i], function (err, results) {
                    joinedSet = joinedSet.concat(results);
                    responsesReceived += 1;

                    if (responsesReceived === length) {
                        callback(joinedSet);
                    }
                });
            }
        } else {
            callback([]);
        }

        return joinedSet;
    }
function runSubqueries ( subQueries , callback , collection ) { var i , responsesReceived = 0 , length = subQueries . length , joinedSet = [ ] ; //The array where the results are going to get stuffed if ( subQueries . length > 0 ) { for ( i = 0 ; i < subQueries . length ; i += 1 ) { collection . aggregate ( subQueries [ i ] , function ( err , results ) { joinedSet = joinedSet . concat ( results ) ; responsesReceived += 1 ; if ( responsesReceived === length ) { callback ( joinedSet ) ; } } ) ; } } else { callback ( [ ] ) ; } return joinedSet ; }
Run the sub queries individually, leveraging concurrency on the server for better performance.
Run the sub queries individually leveraging concurrency on the server for better performance .