Add MongoDB aggregation to Collections

It would be great to allow mongodb aggregation. I am personally using geoNear for example.
This commit is contained in:
Sebastian Grebe 2018-04-21 11:40:56 +02:00 committed by GitHub
parent 299d83df98
commit 90c3e8d2cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import { runCallbacks } from './callbacks.js';
import { getSetting, registerSetting } from './settings.js';
import { registerFragment, getDefaultFragmentText } from './fragments.js';
import escapeStringRegexp from 'escape-string-regexp';
wrapAsync = (Meteor.wrapAsync)? Meteor.wrapAsync : Meteor._wrapAsync;
// import { debug } from './debug.js';
registerSetting('maxDocumentsPerRequest', 1000, 'Maximum documents per request');
@ -79,6 +80,16 @@ Mongo.Collection.prototype.addView = function (viewName, view) {
this.views[viewName] = view;
};
/**
* @summary Allow mongodb aggregation
* @param {Array} pipelines mongodb pipeline
* @param {Object} options mongodb option object
*/
Mongo.Collection.prototype.aggregate = function (pipelines, options) {
var coll = this.rawCollection();
return wrapAsync(coll.aggregate.bind(coll))(pipelines, options);
};
// see https://github.com/dburles/meteor-collection-helpers/blob/master/collection-helpers.js
Mongo.Collection.prototype.helpers = function(helpers) {
var self = this;