S
S
Stanislav2017-07-17 17:51:25
MongoDB
Stanislav, 2017-07-17 17:51:25

Why is the date cached when saving a record in MongoDB?

When registering a user, in the mongoose schema I increase the date by 7 days.
Here is an example:

{
    reset: { type: Date, default: increaseDate(7);}
}
function increaseDate(n) {
    return new Date(new Date().setDate(new Date().getDate()+n));
}

In general, I take today's date and plus 7 days, but the problem is that the node seems to cache the date during the last restart of the script. The script was restarted 8 days ago, the user logged in today and the reset field contains yesterday's date.
How to be? What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-07-17
@ms-dred


schema.pre('save', function(next) {
// do stuff
next();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question