mongodb比较复杂的综合统计计算,性能还不差
2014-11-18 15:59
537 查看
db.app_users.aggregate([ { $project:{ fs:1, ls:1, subt:{$subtract:['$ls','$fs']}, days714:{ $cond: [ { $gte:['$ls',(Math.round((new Date()).getTime() / 1000)-14*24*60*60)]},1,0] }, days1430:{ $cond: [ { $and:[ { $lte:['$ls',(Math.round((new Date()).getTime() / 1000)-14*24*60*60)]}, { $gte:['$ls',(Math.round((new Date()).getTime() / 1000)-30*24*60*60)]} ] },1,0] }, days30:{ $cond: [ { $lte:['$ls',(Math.round((new Date()).getTime() / 1000)-30*24*60*60)]},1,0] }, days815:{ $cond: [ { $and:[ { $lte:['$ls',(Math.round((new Date()).getTime() / 1000)-8*24*60*60)]}, { $gte:['$ls',(Math.round((new Date()).getTime() / 1000)-15*24*60*60)]} ] },1,0] }, days1531:{ $cond: [ { $and:[ { $lte:['$ls',(Math.round((new Date()).getTime() / 1000)-15*24*60*60)]}, { $gte:['$ls',(Math.round((new Date()).getTime() / 1000)-31*24*60*60)]} ] },1,0] }, days31:{ $cond: [ { $lte:['$ls',(Math.round((new Date()).getTime() / 1000)-31*24*60*60)]},1,0] }, } }, { $match:{ subt:{$lt:24*60*60}, ls:{ $lt:(Math.round((new Date()).getTime() / 1000)-7*24*60*60)} } }, { $group:{ '_id':null, days7_14: {$sum: "$days714"}, days14_30: {$sum: "$days1430"}, days_more30: {$sum: "$days30"}, days8_15: {$sum: "$days715"}, days15_31: {$sum: "$days1531"}, days_more31: {$sum: "$days30"} } } ])
相关文章推荐
- MongoDB与Tokyo Tyrant性能比较(1):基础CRU操作
- MongoDB与Tokyo Tyrant性能比较(2):并发写入操作
- MongoDB与Tokyo Tyrant性能比较:基础CRU操作(转自:老赵)
- R(1.5.1)和其他统计语言的性能比较(2003年)
- R(1.9.0)和其他统计语言的性能比较(2003年)
- 今天写了统计的比较复杂的SQL
- mongoDB、redis、Mysql的count、limit性能比较与分析
- NoSQL数据库性能比较:MongoDB vs Redis vs Tokyo Tyrant
- NoSQL数据库性能大比较:MongoDB、Redis、Tokyo Tyrant
- MongoDB与Tokyo Tyrant性能比较(2):并发写入操作
- MongoDB,Redis,Tokyo Cabinet,BerkeleyDB之性能比较
- MongoDB,Redis,Tokyo Cabinet,BerkeleyDB之性能比较
- apache日志的不同统计方法性能比较
- 1.圈选删除节点慢的问题已经解决;2.后处理中,统计量比较多时,计算慢,进一步确定了问题的原因
- MongoDB与Tokyo Tyrant性能比较(1):基础CRU操作
- MongoDB,Redis,Tokyo Tyrant(Tokyo Cabinet)性能测试比较
- NoSQL数据库性能比较:MongoDB vs Redis vs Tokyo Tyrant
- MongoDB中复杂的分组查询统计(MapReduce)
- Mongodb的基本性能统计工具简单记录