Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-5309

FIWARE.Question.Tech.Apps.DataViz-SpagoBI.: MongoDb: Aggregation using Groovy language

    Details

      Description

      Created question in FIWARE Q/A platform on 08-09-2015 at 16:09
      Please, ANSWER this question AT http://stackoverflow.com/questions/32459956/mongodb-aggregation-using-groovy-language

      Question:
      MongoDb: Aggregation using Groovy language

      Description:
      Iam using groovy scripting under SpagoBI. I want to use aggregation.
      I want for example to execute the following aggregation:

      db.myCollection.aggregate(
      [
      {
      $group : {
      _id : { day:

      { $dayOfMonth: "$recvTime" }

      }

      }
      }
      ]
      )

      I tried:

      DBObject projectFields = new BasicDBObject('$dayOfMonth',"recvTime");
      DBObject project=new BasicDBObject('$project',projectFields)

      DBObject groupFields = new BasicDBObject( "_id",project);

      DBObject group = new BasicDBObject('$group', groupFields);

      iterable = db.getCollection('myCollection').aggregate(group)

      I got this error:

      An unexpected error occured while executing dataset:

      { "serverUsed" : "192.168.1.160:27017" , "errmsg" : "exception: invalid operator '$project'" , "code" : 15999 , "ok" : 0.0}

      Any ideas?

      Updates:
      the query executed in Mongo shell

      db['cygnus_/kurapath_enocean_power_enocean'].aggregate(
      ... [
      ... {
      ... $group : {
      ... _id : { day:

      { $dayOfMonth: "$recvTime" }

      }
      ... }
      ... }
      ... ]
      ... );
      { "_id" :

      { "day" : 9 }

      }
      { "_id" :

      { "day" : 8 }

      }
      { "_id" :

      { "day" : 7 }

      }
      { "_id" :

      { "day" : 4 }

      }
      { "_id" :

      { "day" : 3 }

      }

      the data stored in mongo db:

      db['cygnus_/kurapath_enocean_power_enocean'].find()

      { "_id" : ObjectId("55e81e9631d7791085668331"), "recvTime" : ISODate("2015-09-03T10:19:02Z"), "attrName" : "power", "attrType" : "string", "attrValue" : "2085.0" } { "_id" : ObjectId("55e81e9631d7791085668332"), "recvTime" : ISODate("2015-09-03T10:19:02Z"), "attrName" : "power", "attrType" : "string", "attrValue" : "2085.0" } { "_id" : ObjectId("55e81e9831d7791085668333"), "recvTime" : ISODate("2015-09-03T10:19:04Z"), "attrName" : "power", "attrType" : "string", "attrValue" : "2077.0" }

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2015-11-14 21:05|CREATED monitor | # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2015-11-14 21:05|CREATED monitor | # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2015-11-15 00:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2015-11-15 00:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2015-11-15 03:05|UPDATED status: transition Answered| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2015-11-15 03:05|UPDATED status: transition Answered| # answers= 1, accepted answer= True
        Hide
        zerbetto Davide Zerbetto added a comment -

        Answered by SpagoBI team in the stackoverflow thread

        Show
        zerbetto Davide Zerbetto added a comment - Answered by SpagoBI team in the stackoverflow thread

          People

          • Assignee:
            zerbetto Davide Zerbetto
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: