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: &nbsP; " $days 714 "}, days14_30: {$sum: " $days 1430 "}, days_more30: {$sum: "$days"}, days8_15: {$sum: "$days 715"}, days15_31: {$sum: "$days 1531"}, days_more31: {$sum: "$days"}     } }])
MongoDB more complex comprehensive statistical calculation, performance is not bad