I’m really confused and have been scratching my head over this for a few days now. I have a PHP script that stores some user profiles in a MongoDB. Users can login, change a few fields, and logout. When they login, it records the lastlogin date/time, and when you modify something it records the last modified date/time using the MongoDate object.
It works.. but sometimes.. and of course what appears randomly, the dates reset for specific documents to ‘ISODate("1969-12-31T16:00:00-08:00")‘
My documents store the dates like:
dates: {
created: ISODate("1969-12-31T16:00:00-08:00"),
lastlogin: ISODate("1969-12-31T16:00:00-08:00"),
modified: ISODate("1969-12-31T16:00:00-08:00")
},
My PHP code looks like:
$collection->update(array('account.email' => $email), array('$set' => array('dates.lastlogin' => new MongoDate())));
Anyone have any ideas why?
MongoDate()represents a number of seconds since January 1st 1970 (ref: MongoDate::__construct).The date you are seeing is the result of passing a value of an undefined variable or 0 (aka the unix epoch) to
MongoDate().Normally this value would be saved in MongoDB as:
However, because you have set your timezone to
GMT -8you are seeing the date offset by 8 hours, which becomes: