According to Meteor v1.0.4:
Provide direct access to collection and database objects from the npm Mongo driver using the new rawCollection and rawDatabase on Mongo.Collection
So you can call collection.rawCollection() to get the base collection object:
var rawCollection = Orders.rawCollection();
This rawCollection has a group method that is equivalent to the group method in the MongoDB shell. The underlying API node is asynchronous, so you want to somehow convert it to a synchronous function. We cannot use Meteor.wrapAsync directly, since group accepts function arguments that are not the main callback, so we will deal with the shell:
function ordersGroup(/* arguments */) { var args = _.toArray(arguments); return Meteor.wrapAsync(function (callback) { rawCollection.group.apply(rawCollection, args.concat([callback])); })(); }
Inside your method, you can call ordersGroup , like you, db.orders.group in the Mongo shell. However, the arguments are passed separately, and not in the object:
ordersGroup(keys, condition, initial, reduce[, finalize[, command[, options]]])
See this documentation for more information (although note that the callback parameter should be omitted since our processing of async packets is from this).
So, you have to pass them separately:
var result = ordersGroup(
Of course, this only works on the server, so make sure your method is in the server-only code (preferably in the server subdirectory or inside if (Meteor.isServer) ).