You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using aggregation to get items in a month, grouped by serviceTypeId and plannedStartDate or executedEndDate. I'm using something like this (no date is mandatory):
Meteor.publish("serviceTypesCounts",function(startDate,endDate){// init dates to current month if not provided:startDate=startDate||moment().startOf('month').toDate();endDate=endDate||moment().endOf('month').toDate();// Remember, ReactiveAggregate doesn't return anythingReactiveAggregate(this,Services,[{$match: {// match current user's projectId and either planned or executed date exists, and any of those dates are inside startDate, endDate range:$and: [{projectId: getCurrentProjectId(this.userId)},// plannedStartDate or executedStart date exists:{$or: [{plannedStartDate: {$exists: true}},{executedStartDate: {$exists: true}}]},// plannedStartDate is in startDate, endDate range or it doesn't exist and executedStartDate is:{$or: [{plannedStartDate: {$gte: startDate,$lte: endDate}},{$and: [{executedStartDate: {$gte: startDate,$lte: endDate}},{plannedStartDate: {$exists: false}}]}]}]}},{$group: {'_id': {serviceTypeId: "$serviceTypeId",year: {$cond: [{$ifNull: ['$plannedStartDate',0]},{$year: '$plannedStartDate'},{$year: '$executedStartDate'}]},month: {$cond: [{$ifNull: ['$plannedStartDate',0]},{$month: '$plannedStartDate'},{$month: '$executedStartDate'}]},day: {$cond: [{$ifNull: ['$plannedStartDate',0]},{$dayOfMonth: '$plannedStartDate'},{$dayOfMonth: '$executedStartDate'}]},},'count': {$sum: 1}}},{$project: {_id: {$concat: ['$_id.serviceTypeId','-',{$substr: ["$_id.year",0,4]},{$substr: ["$_id.month",0,2]},{$substr: ["$_id.day",0,2]}]},year: '$_id.year',month: '$_id.month',day: '$_id.day',count: '$count'}// Send the aggregation to the 'clientReport' collection available for client use}],{clientCollection: "ServiceTypesCounts"});});
Now, thing is: I want to get field serviceType.name inside original objects (or event the full object), how can a I do this?
It would be great to get that field even if I'm not grouping by it, but in this case I don't care as it is the readable representation for serviceTypeId.
Thanks!
The text was updated successfully, but these errors were encountered:
Hi,
Let's say I got this object structure in a collection:
I'm using aggregation to get items in a month, grouped by
serviceTypeId
andplannedStartDate
orexecutedEndDate
. I'm using something like this (no date is mandatory):I works, I'm getting results like this:
Now, thing is: I want to get field
serviceType.name
inside original objects (or event the full object), how can a I do this?It would be great to get that field even if I'm not grouping by it, but in this case I don't care as it is the readable representation for serviceTypeId.
Thanks!
The text was updated successfully, but these errors were encountered: