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

后端 未结 8 1694
无人及你
无人及你 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

    MongoDB's documentation suggests that you save the timezone offset alongside the timestamp:

    var now = new Date();
    db.data.save( { date: now,
                    offset: now.getTimezoneOffset() } );
    

    This is of course not the ideal solution – but one that works, until we have in MongoDb's aggregation pipeline a proper $utcOffset function.

提交回复
热议问题