Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Mongoose和Nodejs中的中间件更新last_edit 让我们考虑这个模式: var elementSchema = new Schema({ name: String, last_edit: { type: Date, default: Date.now } });_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 使用Mongoose和Nodejs中的中间件更新last_edit 让我们考虑这个模式: var elementSchema = new Schema({ name: String, last_edit: { type: Date, default: Date.now } });

Node.js 使用Mongoose和Nodejs中的中间件更新last_edit 让我们考虑这个模式: var elementSchema = new Schema({ name: String, last_edit: { type: Date, default: Date.now } });,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,现在,每次我更新任何元素。name我希望mongoose直接更新last\u edit时间 信中说: 我可能会更新它而不是//do stuff,但是要保存的文档没有传递, 任何提示?在'save'中间件中,此是对正在保存的文档的引用: schema.pre('save', function (next) { this.last_edit = Date.now(); next(); }); 在'save'中间件中,这是对正在保存的文档的引用: schema.pre('save', fun

现在,每次我更新任何元素。
name
我希望mongoose直接更新
last\u edit
时间

信中说:

我可能会更新它而不是
//do stuff
,但是要保存的文档没有传递,
任何提示?

'save'
中间件中,
是对正在保存的文档的引用:

schema.pre('save', function (next) {
  this.last_edit = Date.now();
  next();
});

'save'
中间件中,
这是对正在保存的文档的引用:

schema.pre('save', function (next) {
  this.last_edit = Date.now();
  next();
});