Using MongoDB in Meteor JS, how do you use Meteor Aggregate properly?
The intended result is to return grouped users by their userId and sum up a boolean field called "progressState" (true/false).
For example the document can have:
user 001 - true
user 001 - false
user 001 - true
user 003 - false
user 005 - true
but the intended result would be:
user 001: 2 true
user 003: 0 true
user 005: 1 true
etc..
My attempt gives the following error:
"exception: FieldPath field names may not start with '$'."
Here is my Meteor Code:
Meteor.publishComposite('completedLB', {
find: function() {
return userCompleted.aggregate([
{
$match: {
"progressState": "true"
}
},
{
$group: {
"_id": "$userId",
"count": {
"$sum": "$progressState"
}
}
},
{
$sort : {
"$progressState": -1
}
}
]);
}
});