0

I need to implement some simple aggregations in my app powered by Grails 1.3.7. The mongodb-plugin of 1.0.0.RC3 ships with gmongo 0.9.1, where the aggregate functions are not implemented.

How can I solve the problem? Are there any hooks to call java-mongo API directly, or maybe there's some other plugin releases which allow aggregations?

TIA

4

4 回答 4

1

似乎 Mongo 聚合 API 从 2.1开始就存在,可能您可能需要升级您的库。这是讨论访问低级 api的 mongodb 插件文档。对于 grails 1.3.7,请参阅此博客以获取有关如何将更多最新的 mongo 库添加到您的 Grails 应用程序的详细信息,这篇文章似乎也有同样的问题。

希望能帮助到你。

于 2013-07-28T11:23:48.130 回答
0

好吧,用现有的 gmongo/mongo-GORM 似乎是不可能的。版本冲突太多:不同的 mongo java 驱动程序、不同的 groovy 版本等。我看到了很多 ClassNotFoundExceptions 等。

幸运的是我现在不需要聚合功能,所以我将等待并稍后升级到 grails 2.x 和 mongo-GORM 1.3++

于 2013-08-10T20:28:35.027 回答
0

聚合仅适用于 GMongo 1.0+。

于 2013-08-01T16:21:17.750 回答
0

所以,我做到了!

流了一点血,我找到了一种在 gmongo 0.9.1 / mongodb 1.0.0.RC3 / Grails 1.3.7 中使用聚合的方法!

如何:

  1. 您需要将 mongo-java-driver 替换为较新的版本(我现在使用的是最新版本 2.9.3)。在 Grails 中,它看起来像:

    依赖项 { 编译 'org.mongodb:mongo-java-driver:2.9.3' }

  2. 在 BootStrap 或在我的情况下 Plugin-descriptor 添加以下行:

    DBCollectionPatcher.PATCHED_METHODS << '聚合'

  3. 聚合调用如下所示:

    def res = Task.collection.aggregate( [ $group:[ _id:'totalTime', time:[ $sum:'$time' ] ] ], [] as DBObject ).results()

它就像一个魅力!

于 2013-10-16T14:30:24.103 回答