grapher/lib/aggregate.js

16 lines
517 B
JavaScript
Raw Permalink Normal View History

import { Promise } from 'meteor/promise';
Mongo.Collection.prototype.aggregate = function(pipelines, options = {}) {
2017-11-26 23:42:27 +02:00
const coll = this.rawCollection();
let result = Meteor.wrapAsync(coll.aggregate, coll)(pipelines, options);
2018-06-07 01:48:12 +03:00
// We need to check If it's an AggregationCursor
// The reason we do this was because of the upgrade to 1.7 which involved a mongodb driver update
if (Array.isArray(result)) {
return result;
} else {
return Promise.await(result.toArray());
}
2017-11-26 23:42:27 +02:00
};