Created
May 3, 2015 13:51
-
-
Save grabbou/ab21138ebf8859799bfb to your computer and use it in GitHub Desktop.
Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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