问题
Is a Mongo-style db.collection.group(...) query possible in Meteor, yet? I was hoping i could run something like this on the server (coffeescript):
Meteor.publish "top10", ->
Records.group
key: {name:true}
reduce: (obj, agg) -> agg.count++
initial: {count:0}
回答1:
Actually not yet.
Meteor uses node-mongo-native to do CURD in the server-side, whilst minimongo in the client-side. And Meteor keeps same API in the both side.
The document says -
In this release, Minimongo has some limitations:
...
findAndModify, upsert, aggregate functions, and map/reduce aren't supported.
However, node-mongo-native supports them, so I think Meteor just doesn't expose the related API for us. You can take a look at packages/mongo-livedata/mongo_driver.js, and help yourself.
回答2:
Here's a working example of how to do this: https://github.com/meteor/meteor/pull/644
来源:https://stackoverflow.com/questions/11266977/are-group-by-aggregation-queries-possible-in-meteor-yet