0

I am trying to run the code given in this link... MongoDB aggregation time series

Can anyone please help to run this code using java... I tried but getting unknown group operator 'hour'

My code for $match and $group :

DBObject match = new BasicDBObject("$match", new BasicDBObject("Date", new BasicDBObject("$gt", gtDate).append("$lte", lteDate)));


DBObject group = new BasicDBObject("$group",
            new BasicDBObject("0",new Document("$push",new Document("doc","$Vals.0")).
                    append("hour", "$_id.hour").append("min", new Document("$literal",0)))
        );

not sure it's right way or not.Please help

Community
  • 1
  • 1
yog
  • 199
  • 1
  • 2
  • 20
  • 1
    Would you care to explain the background of your question; what is it that you are trying to aggregate, what is your expected output given some sample documents? – chridam Jul 27 '16 at 11:43

1 Answers1

0

From the snippet you provided here's what your group statement looks like (hint you can just log/print the group DBObject to see the json):

{ "$group" : { "0" : { "$push" : { "doc" : "$Vals.0"} , "hour" : "$_id.hour" , "min" : { "$literal" : 0}}}}

Notice how your $group is missing the _id like in the example you provided? That's the root of your syntax error.

helmy
  • 9,068
  • 3
  • 32
  • 31