Aggregation help (meteorhacks:aggregate)


Its the first time I get to use aggregation with Meteor, and I seem to get it all working except that I get an error in browsers console. So the method looks like that:

		'reports.aggregation' (companyId) {
			check(companyId, String);
			const pipeline = [
				{$match: {companyId: companyId}},
				{$group: {
					_id: {
				    year:  { $year: "$timestamp" },
				    month: { $month: "$timestamp" },
				    day:   { $dayOfMonth: "$timestamp" }
			    count:{$sum: 1 }
			return Reports.aggregate(pipeline);

so I get an error and results after the error in my browser console.

Exception while simulating the effect of invoking 'reports.aggregation' TypeError: Reports.aggregate is not a function

I was wondering maybe I need to import meteorhacks:aggregate on the server? Did tried few import strings but unsuccessfully. Anyone have ideas?


The error comes from the simulation being run on the client. meteorhacks:aggregate is a server-only package, so doesn’t exist on the client.

If you wrap the “insides” of your method in a Meteor.isServer block or ensure your method is only available to the server it will run without error.

The fact that you are getting this error suggests that your method currently exists on the client and the server.


Cool! Moved it to Meteor.isServer and it solved the error.


1 Like