Hello I am working in node js + mongodb.
When I insert the data into collection the data is stored default ISODate eg. ISODate("2016-06-17T13:00:21.665Z")
I want to insert the date fields should be store in UTC.
Its already stored in UTC format or need to change anything in code ?
Please anyone suggest me.
My Code:
var query = {};
query.created_by = 'admin';
query.created_on = new Date();
var collection = mongoUtil.list;
collection.insert(query, function(err, item) {
if (!err && item) {
console.log("success");
} else {
console.log("error");
}
});
Mongo inserted data:
{ "created_by" : "admin", "created_on" : ISODate("2016-06-17T13:00:21.665Z") }
I checked the refference - Mongo UTC Refference From Document:
- Date() returns the current date as a string in the mongo shell.
- new Date() returns the current date as a Date object. The mongo shell wraps the Date object with the ISODate helper. The ISODate is in UTC.