meteorhacks/meteor-aggregate

when will MongoDB 3.6 be supported?

Closed this issue · 8 comments

I updated to Meteor 1.7, without changing the code, I now get an AggregationCursor returned and not the result of the last aggregation, see http://mongodb.github.io/node-mongodb-native/3.0/api/AggregationCursor.html

Same here. I have tried using async/await along with .toArray() with the cursor but unable to figure out how to? Any ideas?

yes sure, the node-mongodb driver works as described in the documentation. Meteor also updated that lib internally to v3.0.7 which is great. It's just this package here that hasn't adopted that yet :)

I couldn't really switch to async/await in that part of the code, so I wrapped it the callback way:

const pipelineCursor = Meteor.users["aggregate"]([ ... ]);
const firstElem: any = Meteor.wrapAsync(pipelineCursor.next, pipelineCursor)();
jadus commented

#47 is fixing this issue

Thanks @maxfriedmann. That was helpful. We use aggregation quite a bit throughout our app so this might be some work to identify all over and fix.

@jadus Great! Thanks for the reference. I am switching to https://github.com/sakulstra/meteor-aggregate considering there are PRs waiting here since 2015. shout out to @sakulstra for the fork!!

Simplest solution of resolve this problem that I found is:

meteor remove meteorhacks:aggregate  
meteor add sakulstra:aggregate

It has the same interface but works with Meteor 1.7

Alternatively, you use the native rawCollection like this:

Meteor.methods({
  async aggregateMyStuff() {
    const pipeline = [ ... ];
    const options = { ... };
    let result = await (MyCollection.rawCollection().aggregate(pipeline, options)).toArray();
    return result;
  },
});

I'm actually wanting to call MyCollection.rawCollection().aggregate() with a callback and not run it synchronously. As I'm worried about blocking the event loop. Is there a way to call aggregate and pass a callback that fires when it's done to process the results?

Native aggregation works now perfectly!