Failure to load data from aggregate/pipeline

Error on server console: UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded

Meteor 1.8.1

Project worked fine at 1.6.x, MongoDB 3.2.x

mlab pushed me to mongo 3.6.x and now some of my charts (chart.js) and tables (aslagle:reactive-table) aren’t working.

Both of these are generated via aggregate/pipeline (example below).

Long story short, I’ve neglected this project for several months and just getting back to it, ran into this issue, and tried updating to 1.8.1. Which has me at mongo 4.0.6

Charts and tables still not working and I think it’s because I’m missing some update to the syntax/structure in the aggregates and/or pipelines. I could very well be wrong here as I’m rusty, not a dev by trade and as mentioned haven’t touched this in a few months.

Here’s one failing aggregate/pipeline that’s used to draw a line chart (Chart.js):

pointTrendsSprt: function(uid, sp){
  		var pipeline = [
  							{ $match: {"userId": uid, "sport":sp, "slate": {$exists: true} } },
  							{ $project: {slate:1, sport:1, pointsWon:1, createdAt:1} },
  							{ $group: {
  										_id: "$slate",
  										sport: {"$addToSet": "$sport"},
  										pointsWon: {"$sum": "$pointsWon"},
  										createdAt: {"$max": "$createdAt"}
  							          } 
  							},
  							{ $sort: { "createdAt":1 } }
  						];

  		return Results.aggregate(pipeline);
  	},

Here’s another that’s used in a aslagle:reactive-table:

allXteam: function(uid){
		var pipeline = [
							{ $match: {"userId": uid, "win": "true"} },
							{ $project: {team:1, match:1, play:1, Count: "$count"} },
							{ $group: 
								{_id: "$team", 
								play: {"$addToSet": "$play"},
								count:{$sum:1}} 
							}
						];

		return Picks.aggregate( pipeline );

	},

Both of these are in a methods.js file in the server folder. I use Meteor.call on the client side js file to set session vars where the chart and tables pull from.

As mentioned, I think I need to fix something in my aggregations/pipelines but tried adding in “cursor” and “explain” and am either not doing that right or just wrong in that assumption.

Any suggestions/guidance would be greatly appreciated.

Try async/await. I think aggregate returns a promise.

I found that this solution worked:

Collection.rawCollection().aggregate().toArray()

Interestingly, I’m still getting a
reactiveTable error: argument is not an instance of Mongo.Collection, a cursor, or an array
error in the browser console although the session vars do get set just fine.

There is a note in that linked post above from robfallows about using async/await as well and on my first try was not able to eliminate the client side error but it could be my ugly factoring. I will post an update if I’m able to resolve.

One note, for some reason I don’t have to do this for ALL of my aggregates. Just a few.