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.
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) });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With