Advertisement
krasi1105

Untitled

Dec 2nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let simpleQuery = (startDate, millis) => {
  2.   return Entry.aggregate([{
  3.     $match: {
  4.       date: {
  5.         $gte: startDate
  6.       }
  7.     }
  8.   },
  9.   {
  10.     $project: {
  11.       cpu: '$data.cpu',
  12.       date: 1
  13.     }
  14.   },
  15.   {
  16.     $group: {
  17.       _id: {
  18.         $floor: {
  19.           $divide: [{
  20.             $subtract: ['$date', startDate]
  21.           }, millis]
  22.         }
  23.       },
  24.       avgCpu: {
  25.         $avg: '$cpu'
  26.       },
  27.       avgDate: {
  28.         $avg: {
  29.           $sum: {
  30.             $subtract: ['$date', TheEpoch]
  31.           }
  32.         }
  33.       }
  34.     }
  35.   },
  36.   {
  37.     $project: {
  38.       _id: 0,
  39.       avg: '$avgCpu',
  40.       date: '$avgDate'
  41.     }
  42.   },
  43.   {
  44.     $sort: {
  45.       date: 1
  46.     }
  47.   }
  48.   ])
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement