If I try to put a date field in a document (BSON) and write it to Mongo, BSON writes it to UTC. For example, date
DateTime dateTime = new DateTime("2015-07-01");
Document doc = new Document("date", dateTime.toDate());
will be saved as
"date" : ISODate("2015-06-30T18:30:00Z")
in mongo. And, if I extract it using the same Java driver, I get it as
Wed Jul 01 00:00:00 IST 2015
Great. Isn't that a solution? I mean, why can't I keep my date the way I want it? What if I need to request a database from another time zone? Am I getting different results? The date field is an important part of Mongo with a rich set of operators wrapped around it. However, why does Mongo not provide such flexibility? Thanks
source
share