小编Sha*_*son的帖子

Mongoose发现并找到一个中间件无法正常工作

如果有以下架构和中间件挂钩,而是findfindOne挂钩从来没有被调用.在saveupdate预期挂钩工作.根据Mongoose Middleware文档,这应该是可用的.

// define the schema for our recs model
var recSchema = mongoose.Schema({
  dis: String,  // rec display
  mod: String   // modified date (HAYSTACK FORMAT)
}, {
  strict: false
});

// create the model for recs
var model = recsdb.model('recs', recSchema);

recSchema.pre('save', function(next) {
  this.mod = HDateTime.now(HTimeZone.UTC).toZinc();
  next();
});
recSchema.pre('update', function(next) {
  this.mod = HDateTime.now(HTimeZone.UTC).toZinc();
  next();
});
recSchema.pre('find', function() {
  console.log("Pre Find");
});
recSchema.pre('findOne', function() {
  console.log("Pre Find One"); …
Run Code Online (Sandbox Code Playgroud)

middleware find mongoose node.js

1
推荐指数
1
解决办法
4413
查看次数

标签 统计

find ×1

middleware ×1

mongoose ×1

node.js ×1