If I try to put a date field in a Document (BSON) and write it to Mongo, BSON writes it in UTC. For example, a date
DateTime dateTime = new DateTime("2015-07-01");
Document doc = new Document("date", dateTime.toDate());
will be stored as
"date" : ISODate("2015-06-30T18:30:00Z")
in Mongo. And, if I retrieve it using the same Java Driver I get it as
Wed Jul 01 00:00:00 IST 2015
Great. Is there no solution to this? I mean, why can't I store my date as I want it? What If I need to query on the DB from another time zone? I will be getting different results? Date field is an important part of Mongo with a rich set of operators wrapped around it. Still, why doesn't Mongo provide this flexibility? Thanks
Date
type represents an instant in time, internally stored as milliseconds since the Unix epoch. If you don't want to store an instant in time,Date
isn't going to help you :( – MastersonDate
type means. It's not clear what behaviour you're trying to achieve. – Masterson