在我们更改文档其他值后,mongoose是否会“重启”(Does mongoose expires 'restarts' after we alter the document other values)

假设我有一个Schema如下:

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);

所以我想知道更新文档是否会重置文档的过期时间,如果其他更改name属性,或者只有在createdAt值更改时才重新启动(重置)时间。

Mongoose文档对此没有任何意义。

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.

最满意答案

否,修改documentAt以外的文档字段对文档何时到期没有影响。

该文件将在以下current time >= createdAt + 3600到期: current time >= createdAt + 3600

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

在我们更改文档其他值后,mongoose是否会“重启”(Does mongoose expires 'restarts' after we alter the document other values)

假设我有一个Schema如下:

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);

所以我想知道更新文档是否会重置文档的过期时间,如果其他更改name属性,或者只有在createdAt值更改时才重新启动(重置)时间。

Mongoose文档对此没有任何意义。

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.

最满意答案

否,修改documentAt以外的文档字段对文档何时到期没有影响。

该文件将在以下current time >= createdAt + 3600到期: current time >= createdAt + 3600

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