Himanshu Mittal
Himanshu Mittal

Reputation: 612

Does mongoose expires 'restarts' after we alter the document other values

Suppose i have a Schema as follows:

const UserSchema = new mongoose.Schema({
    name: String,
    createdAt: { type: Date, default: Date.now, expires: 3600 }
});

const User= mongoose.model('User', UserSchema);

const user = new User({name: 'Me'});

console.log(user);

setTimeout(function () {
    User.update({name: 'Me'}, {name: 'You'}).exec((err, user) => console.log(user));
    //update statement is incorrect, but i think you got my point
}, 2000);

So i wanted to know if updating the document will reset the document's expire time if other if change the name attribute, or the time will restart (reset) only if the createdAt value is change.

The Mongoose documentation does not have any point on this.

Upvotes: 0

Views: 276

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312129

No, modifying a document's fields other than createdAt has no effect on when the document expires.

The document will expire when: current time >= createdAt + 3600

Upvotes: 1

Related Questions