Are “group by” aggregation queries possible in Meteor, yet?

别来无恙 提交于 2019-12-17 19:42:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!