Skip to content

Instantly share code, notes, and snippets.

@grabbou
Created May 3, 2015 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grabbou/ab21138ebf8859799bfb to your computer and use it in GitHub Desktop.
Save grabbou/ab21138ebf8859799bfb to your computer and use it in GitHub Desktop.
Test
FeedItem.aggregate({
// you want to group all the things by status key
$group: {
_id: '$statusName', // assuming you have `statusName` field in your collections, prefix with `$`.
timeOn: {
// $cond takes 3 arguments as an array, cond expression, true expression and false expression
$cond: [
// if event was active, we want to add the milliseconds to timeOn
{ $eq: [ "$wasActive", true ] },
// so let's compute actual difference
$sum: {
$millisecond: {
$substract: ['$startDate', '$endDate']
}
},
// otherwise,
$substract: {
$millisecond: {
$substract: ['$startDate', '$endDate']
}
}
]
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment