I have a MEAN stack running on AWS Elastic Beanstalk. A common recurring bug is that Node will record an incorrect date value in the database when a user registers. I'm sure i can find a work around for this, but i'm just so puzzled as to why this would be happening seemingly randomly.
Here is a screenshot from the database showing multiple users with the exact same created_at
date although they actually registered on different days and certainly different times. Most of the users shown in this screenshot registered between 11-17 and 11-25
The date is saved in Mongo class method when the user is being saved.
UserSchema.pre('save', function(next) {
var currentDate = new Date();
this.updatedAt = currentDate;
if (!this.createdAt)
this.createdAt = currentDate;
next();
});
One thought is the way i have that field declared for the model using a default value. But i'm still not sure how that would explain it.
createdAt: { type: Date, default: new Date() },