How to aggregate by year-month-day on a different timezone

后端 未结 8 1692
无人及你
无人及你 2020-11-29 02:21

I have a MongoDB whom store the date objects in UTC. Well, I want to perform aggregation by year,month day in a different timezone (CET).

doing this, works fine for

8条回答
  •  情话喂你
    2020-11-29 03:03

    I'm not an expert on CET and its relation to UTC, but the following code (for the shell) should do a proper conversion (adding an hour) to a MongoDB date type:

    db.dates.aggregate(
      {$project: {"tDate":{$add: ["$tDate", 60*60*1000]}, "eventCount":1, "customer":1}}
    )
    

    If you run that project command before the rest of your pipeline, the results should be in CET.

提交回复
热议问题