Mongodb not supporting all standard timezones

518 views
Skip to first unread message

Alexandru Martin

unread,
Jun 27, 2019, 3:49:15 PM6/27/19
to mongodb-user
 I have a project:
      {
$project: {
hour:{$hour:{date:'$eventCreatedAt',timezone:'$installation.timezone'}}
}
},

Where my timezone is Etc/GMT+7 but mongodb is throwing an exception.
Screenshot from 2019-06-27 15.42.06.png

Robert Cochran

unread,
Jun 27, 2019, 8:59:50 PM6/27/19
to mongodb-user
Hi,

Given this document:

{
"foo" : 61,
"my_tz_date" : ISODate("2019-06-28T00:20:19.916Z")
}

and this aggregation query:

db.tz1.aggregate( [ 
  { "$project" : { "hour" : { "$hour" : { "date" : "$my_tz_date", "timezone" : "Asia/Bangkok" } } } }
]
)

I received this output:

MongoDB shell version v4.0.10
...
MongoDB server version: 4.0.10
switched to db a_martin
{ "_id" : ObjectId("5d155d4308d7ea229bd0900f"), "hour" : 7 }


So I think you erroneously coded your time zone in "$installation.timezone". Your Olson timezone is in fact "Asia/Bangkok" which is UTC+7. There is no such Olson timezone as "Etc/GMT+7". You may find this list to be helpful.

Please note, I am not an employee of MongoDB, Inc. I'm just another list user trying to help you.

Thanks so much

Bob
   

Robert Cochran

unread,
Jun 27, 2019, 10:05:19 PM6/27/19
to mongodb-user
Hi,

After doing more research on the "Etc" timezone area, it looks like the sign in "Etc/GMT+7" is intentionally inverted, so I mis-identified your true time zone as being in Asia. Perhaps you are somewhere in America. Also, I should have spent a little more time researching how MongoDB really supports time zones. I found SERVER-6310 with more details on time zone support. I get the impression from reading it that the "Etc" area is not supported by MongoDB.

Thanks so much

Bob
Reply all
Reply to author
Forward
0 new messages