0

i want to display a graph of how many visits occur per hour divided per day, in my collection i have objects like this:

{
    "_id" : ObjectId("5ab111a0646e371568c8cfa0"),
    "date" : ISODate("2018-03-20T13:46:30.018Z"),
    "__v" : 0
}

i tried to use the .mapReduce() as specified here https://docs.mongodb.com/manual/aggregation/ and something like this:

db.getCollection('monitors').mapReduce(function(){emit(this.date);}, function(key,values){return Array(values)}, {query: date:'"2018-03-20T13:46:30.018Z"'}, out:"order_totals"})

just to try to collect all the visits in that day but it doesn't work.

William.P
  • 114
  • 9
  • it gives me some errors "command failed" and aggregate failed – William.P Mar 20 '18 at 15:45
  • What is your MongoDB version and which query did you run? – chridam Mar 20 '18 at 15:47
  • MongoDB 3.4.3-10 and Robo3t 1.2 i run you code and gives me errors like "A pipeline stage specification object must contain exactly one field.", "code" : 40323, "codeName" " etc.. i delete the last "count":"$sum":1 and it "works". no errors but no results. – William.P Mar 20 '18 at 16:05
  • ok now it works but it count only the visits in the day, but i also have to group every visit per every hour of every day – William.P Mar 20 '18 at 16:16

0 Answers0