【问题标题】:How to extend the Schema in Mongoose?如何在 Mongoose 中扩展 Schema?
【发布时间】:2012-12-25 02:09:53
【问题描述】:

我想给 Schema 类添加一个静态方法,不改变主 Schema 类怎么办?

谢谢

【问题讨论】:

    标签: schema mongoose


    【解决方案1】:

    website 是这样记录的:

    // assign a function to the "statics" object of our animalSchema
     animalSchema.statics.findByName = function (name, cb) {
     this.find({ name: new RegExp(name, 'i') }, cb);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2018-04-18
      • 2012-07-14
      • 1970-01-01
      相关资源
      最近更新 更多