meteorhacks/meteor-aggregate

Usage with Meteor.users

Closed this issue · 6 comments

Is it possible to use this package with Meteor.users?
I tried the following code:

  var metrics = Meteor.users;
  var pipeline = [
    {$group: {_id: null, month: {$month: "$createdAt"}}}
  ];
  var result = metrics.aggregate(pipeline);
  return result;

But it throws this error:

I20141106-17:30:35.662(1)? Exception while invoking method 'aggregatedSignups' TypeError: Object #<Object> has no method 'aggregate'
I20141106-17:30:35.662(1)?     at Mongo.Collection.aggregate (packages/meteorhacks:aggregate/index.js:21)
I20141106-17:30:35.662(1)?     at Object.App.Admin.aggregatedSignups (packages/app-admin/server/charts.js:6)
I20141106-17:30:35.662(1)?     at Meteor.methods.aggregatedSignups (packages/app-admin/server/charts.js:13)
I20141106-17:30:35.663(1)?     at methodMap.(anonymous function) (packages/meteorhacks:kadira/lib/hijack/wrap_session.js:179)
I20141106-17:30:35.663(1)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20141106-17:30:35.663(1)?     at packages/ddp/livedata_server.js:648
I20141106-17:30:35.663(1)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141106-17:30:35.663(1)?     at packages/ddp/livedata_server.js:647
I20141106-17:30:35.663(1)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141106-17:30:35.663(1)?     at _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646)
rijk commented

+1

rijk commented

thinksoftware:mongo-aggregation does have the option to do this.

Now you can do this.

This does not seem to be working for me. I have an almost similar method except that my pipeline is slightly different. However I receive the same error.

+1 It is still not working for met too

It might be a wrapping problem, something is probably wrapping Meteor.users directly (not Mongo.Collection).

Here is what I tried manually and worked for me:

    var rawUsers = Meteor.users.rawCollection();
    var aggregateQuery = Meteor.wrapAsync(rawUsers.aggregate, rawUsers);
    var pipeline = [
        {$match: {}},
        {$project: {username: 1, profile: 1}}
    ];
    var result = aggregateQuery(pipeline);

    return result;

Read more about Meteor.wrapAsync here