Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor rawCollection().aggregate returns type error

Tags:

meteor

On server side I have following code:

Menus = new Mongo.Collection('menus);

Meteor.startup(function() {
    Menus.rawCollection().aggregate([
        {$project: {_id: 1, name: { "$toLower": "$name" } }}
    ]);
});

It gives me TypeError: object is not a function error

at path /home/mateusz/.meteor/packages/npm-mongo/.1.4.39_1.1oqi3la++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/base.js:246

I'm using [email protected] with standard mongo 2.6 backed in.

like image 992
MatiK Avatar asked Apr 28 '26 01:04

MatiK


1 Answers

You could wrap the aggregate function with the Meteor.wrapAsync() method which wraps an asynchronous function so you can call it in a synchronous style but you will lose reactivity:

wrapAsync = (Meteor.wrapAsync)? Meteor.wrapAsync : Meteor._wrapAsync;
Mongo.Collection.prototype.aggregate = function(pipeline, options) {
    var collection = (this.rawCollection) ? this.rawCollection() : this._getCollection();
    return wrapAsync(collection.aggregate.bind(collection))(pipeline, options);
}

Menus = new Mongo.Collection('menus);
Meteor.startup(function() {
    Menus.aggregate([
        {$project: {_id: 1, name: { "$toLower": "$name" } }}
    ]).forEach(function (doc){ console.log(doc) });
});
like image 122
chridam Avatar answered May 03 '26 03:05

chridam