cursor = db.flow.aggregate([
    {
        $match : {
            flowStat : { $bitsAllClear : NumberInt(0x1) },  // 'A' flows only
            timeFirst : { $gte : time_from },
            timeLast  : { $lte : time_to },
        }
    },
    {
        $project : {
            bytes : { $add : [ "$numBytesSnt", "$numBytesRcvd" ] },
            ndpiclass : {
                $split : [ "$nDPIclass", "." ],
            }
        }
    },
    {
        $group : {
            _id : {
                $arrayElemAt : [ "$ndpiclass", 0 ]  // master protocol only
            },
            count : { $sum : "$bytes" }
        }
    },
    {
        $sort : { count : -1 }
    },
    {
        $limit : n
    }
])

cursor.forEach(
    function(e) {
        print(
              e._id + "\t"
            + e.count
        )
    }
)
