Skip to content

Instantly share code, notes, and snippets.

@misutowolf
Created August 22, 2014 21:08
Show Gist options
  • Select an option

  • Save misutowolf/58c83cfd5a299e1ca4c1 to your computer and use it in GitHub Desktop.

Select an option

Save misutowolf/58c83cfd5a299e1ca4c1 to your computer and use it in GitHub Desktop.
classCount: function() {
// Attempt aggregation of the books table to count by class, maybe.
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
var col = db.collection("books");
var aggregateSync = Meteor._wrapAsync(col.aggregate.bind(col));
var pipeline = [
{$group: {_id: "$class", count: {$sum: 1}}},
{$sort: {_id: 1}}
];
var theAnswer = aggregateSync(pipeline);
return theAnswer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment