Mongoose converting stored UTC dates to local time?

mongodb, mongoose, node.js

Solution

Mongoose and node.js aren't doing anything to your dates, it's simply that the JavaScript `Date` type produces a local time string when you call `toString()` on it even though it actually contains the time in UTC.

Explicitly call `toUTCString()` on your `Date` object if you want a UTC time string.

Problem

I'm wondering if this is normal, or if I'm missing something in the schema setup or query process: My app, and mongoose, is correctly storing a date as UTC in mongodb. This is confirmed by viewing the documents via the mongo shell. When I retrieve the documents from mongodb via mongoose the date is now local time. Is there a way to have mongoose keep the date as UTC when queried?

Original source