I am saving DOB in mongodb with new Date(), But it is storing the date with the timezone.
new Date('02-13-1992')
2001-02-12 18:30:00.000Z
As @Wernfried Domscheit mentioned in comments, a date is always stored with timezone in MongoDB. However, one of the canonical ways to store date in UTC timezone would be using $dateFromParts
.
db.collection.update({
key: 1
},
[
{
"$set": {
"dob": {
"$dateFromParts": {
"year": 1992,
"month": 2,
"day": 13
}
}
}
}
])