cursor = db.flow.aggregate([
    {
        $match : {
            flowStat  : { $bitsAnySet : NumberInt(0xc000) },  // IPv4/6
            timeFirst : { $gte : time_from },
            timeLast  : { $lte : time_to },
        }
    },
    {
        $project : {
            proto : "$l4Proto",
            bytes : "$l7BytesSnt",
        }
    },
    {
        $group : {
            _id : "$proto",
            count : { $sum : "$bytes" }
        }
    },
    {
        $addFields : {
            sort_id: {
                $multiply : [
                    sort_order,
                    "$count"
                ]
            },
        }
    },
    {
        $sort : { sort_id : -1 }
    },
    {
        $limit : n
    }
])

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