imports/vx/server/code/serv.js
/**
     * Perform MongoDB query via aggregation pipeline.  In debug mode, this function will perform an explain plan
     * call followed by the actual query. The coding used is inspired Meteor Hacks aggregate package.
     *
     * @param {object} collection MongoDB collection.
     * @param {array} pipeline Aggregation pipeline.
     * @return {array} Results array potentially grouped.
     */
Perform MongoDB query via aggregation pipeline.  In debug mode, this function will perform an explain plan
call followed by the actual query. The coding used is inspired Meteor Hacks aggregate package.

@param {object} collection MongoDB collection.
@param {array} pipeline Aggregation pipeline.
@return {array} Results array potentially grouped.
Perform MongoDB query via aggregation pipeline . In debug mode this function will perform an explain plan call followed by the actual query . The coding used is inspired Meteor Hacks aggregate package . @param { object } collection MongoDB collection . @param { array } pipeline Aggregation pipeline . @return { array } Results array potentially grouped .
async aggregate(collection, pipeline) {
        const coll = collection.rawCollection()
        if (OLog.logLevel >= OLog.logLevelMap.DEBUG) {
            const explainResults = await Meteor.wrapAsync(coll.aggregate.bind(coll))(pipeline, { explain: true }).toArray()
            explainResults.forEach(function(explainResult) {
                if (explainResult.ok) {
                    if (explainResult.stages) {
                        explainResult.stages.forEach((stage, index) => {
                            if (stage.$cursor && stage.$cursor.queryPlanner && stage.$cursor.queryPlanner.winningPlan) {
                                OLog.debug(`serv.js aggregate stage ${index} explain ` +
                                    `winningPlan=${OLog.debugString(stage.$cursor.queryPlanner.winningPlan)}`)
                            }
                        })
                    }
                }
                else {
                    OLog.error(`serv.js aggregate explain plan error explainResult=${OLog.debugString(explainResult)}`)
                }
            })
        }
        return await Meteor.wrapAsync(coll.aggregate.bind(coll))(pipeline).toArray()
    }
async aggregate ( collection , pipeline ) { const coll = collection . rawCollection ( ) if ( OLog . logLevel >= OLog . logLevelMap . DEBUG ) { const explainResults = await Meteor . wrapAsync ( coll . aggregate . bind ( coll ) ) ( pipeline , { explain : true } ) . toArray ( ) explainResults . forEach ( function ( explainResult ) { if ( explainResult . ok ) { if ( explainResult . stages ) { explainResult . stages . forEach ( ( stage , index ) => { if ( stage . $cursor && stage . $cursor . queryPlanner && stage . $cursor . queryPlanner . winningPlan ) { OLog . debug ( ` ${ index } ` + ` ${ OLog . debugString ( stage . $cursor . queryPlanner . winningPlan ) } ` ) } } ) } } else { OLog . error ( ` ${ OLog . debugString ( explainResult ) } ` ) } } ) } return await Meteor . wrapAsync ( coll . aggregate . bind ( coll ) ) ( pipeline ) . toArray ( ) }
Perform MongoDB query via aggregation pipeline.
Perform MongoDB query via aggregation pipeline .