Hello everyone!
Sorry if my question is silly, as I have just started to learn MongoDB, but I can not figure out how to solve one problem, using MongoDB. Therefore ask your advices here.
The main problem - how to work with timezones in MongoDB? In case if we just need to store time - here is no problem and everything is clear, but so if we don’t have time but only timezone and need to know current time, applying particular timezone ?
As an example, what I mean by that here is small example which I would like to achieve.
Imagine we have users in collection, every user has its own timezone stored in field timezone.
We have scheduled task to send notifications to user, but, time for send it has to be strictly, let’s say, from 9:00 am to 6:00 pm. And of course, in particular moment of time every user will have different time.
The question is: how to select those users which are in period of 9:00 am - 6:00 pm by their local time?
–
In this article: https://docs.mongodb.com/manual/tutorial/model-time-data
Its advised instead of timezone store offset, in this case it’s easy to reconstruct time, but this time will not always be correct. Therefore in my opinion it’s harmful advise.
Imagine that we created record at first of January with Germany timezone (UTC +1) so offset will be 3600. But once German will switch to summer time (29 March 2:00 am) it has to be UTC +2. So we will convert time wrong after that period. That’s why i don’t really like solution with offset.
Here is $where operator which could help, but unfortunately there is no way to work with timezones in JavaScript.
Any advise or thoughts in that?
Thank you in advance,
Best regards,
Alex