Incorrect UTC date in MongoDB Compass
Asked Answered
C

1

5

I package my python (flask) application with docker. Within my app I'm generating UTC date with datetime library using datetime.utcnow().

Unfortunately, when I inspect saved data with MongoDB Compass the UTC date is offset two hours (to my local time zone). All my docker containers have time zone set to Etc/UTC. Morover, mongoengine connection to MongoDB uses tz_aware=False and tzinfo=None, what prevents on fly date conversions.

Where does the offset come from and how to fix it?

Cleaver answered 29/6, 2018 at 9:49 Comment(0)
C
16

Finally, after trying to prove myself wrong, and hairless head I found the cause and solution for my problem.

We are living in the world of illusion and what you see is not what you get!!!. I decided to inspect my data over mongo shell client rather than MongoDB Compass GUI. I figure out that data that arrived to database contained correct UTC date. This narrowed all my previous assumption that there has to be something wrong with my python application, and environment that the application is living in. What left was MongoDB Compass itself. After changing time zone on my machine to a random time zone, and refreshing collection within MongoDB Compass, displayed UTC date changed to a date that fits random time zone.

Be aware that MongoDB Copass displays whatever is saved in database Date field, enlarged about your machine's time zone. Example, if you saved UTC time equivalent to 8:00 am, and your machine's time zone is Europe/Warsaw then MongoDB Compass will display 10:00am.

Cleaver answered 29/6, 2018 at 9:58 Comment(2)
Btw. the way how MongoDB Copass displays date is really bad software decision!Cleaver
Unfortunately, didn't find this answer in time. Spent hours banging my head against the wall, util figuring out the same thing. Whoever designed this tool shouldn't be let near a keyboard againDelectate

© 2022 - 2024 — McMap. All rights reserved.