Skip to content

Commit

Permalink
Handle errors during aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
qualitymanifest committed Sep 3, 2018
1 parent 6e1c973 commit b01be93
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions aggregate.js
Expand Up @@ -27,8 +27,11 @@ export const ReactiveAggregate = function (subscription, collection, pipeline =
// run, or re-run, the aggregation pipeline
const throttledUpdate = _.throttle(Meteor.bindEnvironment(() => {
collection.aggregate(safePipeline).each((err, doc) => {
// first, check to make sure there are documents remaining in the cursor
if (!doc) {
if (err) {
subscription.error(new Meteor.Error("aggregation-failed", err.message));
}
// when cursor.each is done, it sends null in place of a document - check for that
else if (!doc) {
// remove documents not in the result anymore
_.each(subscription._ids, (iteration, key) => {
if (iteration != subscription._iteration) {
Expand All @@ -43,7 +46,7 @@ export const ReactiveAggregate = function (subscription, collection, pipeline =
subscription.ready();
}
}
// cursor is not empty, add and update documents on the client
// cursor is not done iterating, add and update documents on the client
else {
if (!subscription._ids[doc._id]) {
subscription.added(clientCollection, doc._id, doc);
Expand Down

0 comments on commit b01be93

Please sign in to comment.