Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.7.0.1] Meteor.wrapAsync no longer works, returning a cursor instead of ajax results #9936

Closed
WayneUong opened this issue Jun 4, 2018 · 4 comments

Comments

@WayneUong
Copy link

@WayneUong WayneUong commented Jun 4, 2018

We use Meteor.wrapAsync to access the collection aggregation up until meteor 1.6. But after upgrading to 1.7.0.1, the returned result is now a ‌AggregationCursor and no longer a aggregation result.

let rawDonations = Donations.rawCollection();
let rawAggregate = Meteor.wrapAsync(rawDonations.aggregate, rawDonations);
let res = rawAggregate(pipeline);
res => AggregationCursor
@spencern
Copy link

@spencern spencern commented Jun 4, 2018

I think we may be seeing this in Reaction as well.

@sabativi
Copy link

@sabativi sabativi commented Jun 4, 2018

I think it is a change on the mongo driver, add a .toArray at the end, this will return a promise that you can get on the client.
I may be wrong but this works for me, my app is in production with 1.7 and it is the only things that I had to do.

@WayneUong
Copy link
Author

@WayneUong WayneUong commented Jun 4, 2018

@sabativi Works wonderfully. But I struggle to find a way to resolve the promise. I need to get the results, and process them before returning them to clients. I know await can do that but I have to put it in an async function, which is not always possible.

@klaussner
Copy link
Member

@klaussner klaussner commented Jun 4, 2018

@sabativi is right, the new 3.x version of the MongoDB driver passes an AggregationCursor to the callback, whereas the 2.x version passed the aggregation result. From the driver changelog:

Collection.prototype.aggregate now returns a cursor if a callback is provided. It used to return the resulting documents which is the same as calling cursor.toArray() on the cursor we now pass to the callback.

The callback arguments are documented here: http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#~aggregationCallback.

@WayneUong You can use Meteor's Promise.await in non-async functions:

import { Promise } from "meteor/promise";
// ...

// `aggregate` returns a cursor, so you don't need a callback or `wrapAsync`!
const result = Promise.await(rawDonations.aggregate(pipeline).toArray());
@klaussner klaussner closed this Jun 4, 2018
mrsimpson added a commit to assistify/Rocket.Chat that referenced this issue Sep 4, 2018
@see meteor/meteor#9936 - aggregate() now returns a cursor instead of a resolved array
mrsimpson added a commit to assistify/Rocket.Chat that referenced this issue Sep 4, 2018
@see meteor/meteor#9936 - aggregate() now returns a cursor instead of a resolved array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants