Search code examples
mongodbdatetimetimezoneconvert-tz

Convert timestamps stored in a Mongo collection


I have various timestamps stored in Mongo collections, some as floats and some as ints.

They are all stored in BST and the server will be switched to UTC soon. How do I convert them within Mongo to be UTC timestamps?

In MySQL I can do this:

UPDATE `table` SET `field` = CONVERT_TZ(`field`, 'Europe/London', 'UTC');

Is there a Mongo equivalent?


Solution

  • You'll have to use your language of choice and update them one at a time. It should be as simple as a for loop that loads the data and rewrites it.

    Just double-check how your language of choice handles timestamps across timezones. Making such a data change can have all kinds of unexpected effects on production code.