grailsgroovyaggregation-frameworkgmongo

Aggregations in gmongo 0.9.1


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


Solution

  • So, I made it!

    with a little amount of the blood shed, I found a way to use aggregations in gmongo 0.9.1 / mongodb 1.0.0.RC3 / Grails 1.3.7!

    HOWTO:

    1. you need to replace the mongo-java-driver with a newer version (I used the most recent for now 2.9.3). In Grails it looks like:

      dependencies { compile 'org.mongodb:mongo-java-driver:2.9.3' }

    2. In BootStrap or in my case Plugin-descriptor add the following line:

      DBCollectionPatcher.PATCHED_METHODS << 'aggregate'

    3. The aggregation invocation looks like:

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

    and it works like a charm!