Mongological time zone aggregation

Is there a way to consider the time zone when executing a mongo request? We have a problem where, as the clock goes ahead (in BST), our mongo aggregation request does not group the records as expected.

For example, let's say I have 3 entries with createdDatefrom 2017-03-27 13:00:00, 2017-03-28 00:30:00and 2017-03-28 13:00:00. I would expect aggregation to record group 1 for 27/3 and 2 records for 28/3. However, since the second record is stored in the database in UTC format 2017-03-27 23:30:00, aggregation groups have 2 records for 27/3 and only 1 for 28/3.

This is an aggregation request:

{ "$match" : { "$and" : [ 
    { "createdDate" : { "$gte" : { "$date" : {ISODATE}} , 
                        "$lte" : { "$date" : {ISODATE}}}
]}},
{ "$group" : { "_id" : { "_id" : "$id" , 
    "createdDate" : { 
       "year" : { "$year" : "$createdDate"} , 
       "month" : { "$month" : "$createdDate"} , 
       "day" : { "$dayOfMonth" : "$createdDate"}}} , 
    "count" : { "$sum" : 1}
}}

Any ideas how to get around this?

+4
source share

Source: https://habr.com/ru/post/1673596/


All Articles