SELECT COUNT(*), SUM(PKTS), SUM(BYTES) FROM mytable SELECT srcad, srcpo, dstad, dstpo, pro, COUNT(*), SUM(PKTS), SUM(BYTES) FROM mytable WHERE scrpo=80 OR dstpo=80 GROUP BY srcad, scrpo, dstad, dstpo, pro db.mytable.aggregate({$group:{_id:1, sump:{$sum:"$pkts"}, sumb:{$sum:"$bytes"} }}) db.mytable.aggregate([ {$match:{$or:[{scrpo:80},{dstpo:80}]} }, {$group:{_id : {srcad:"$srcad",scrpo:"$scrpo", dstad:"$dstad",dstpo:"$dstpo",pro:"$pro"}, sump:{$sum:"$pkts"}, sumb:{$sum:"$bytes"} }} ]);
根据不同时间分段 以及can’t convert from BSON type NumberDouble to Date错误
db.aggregData.aggregate([ { $project:{ CrawledTweets: 1, newDate: { year:{$year:"$Date"}, month: {$month:"$Date"}, day: {$dayOfMonth:"$Date"}, hour: {$hour: "$Date"}, min: {$minute: "$Date"} } } }, { $group: { _id: "$newDate", tweets: { $sum: "$CrawledTweets"} } } ])