【问题标题】:Mongoose: series of custom instancesMongoose:一系列自定义实例
【发布时间】:2013-01-18 21:26:01
【问题描述】:

根据文档我可以做这样的事情:

var animalSchema = new Schema({ name: String, type: String });

animalSchema.methods.findSimilarTypes = function (cb) {
  return this.model('Animal').find({ type: this.type }, cb);
}

假设我有另一个函数:

animalSchema.methods.owner 如果animalScheme.owner 是 xyz 则过滤,因此它将搜索查询修改为{..., owner: xyz}

是否可以顺序使用实例?我怎样才能做到这一点?

var animalSchema.findSimilarTypes().owner("xyz") ?

有什么提示吗?

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    我相信这不会立即起作用,因为原始函数 findSimilarTypes 不返回架构对象。

    我猜你正在尝试对 jQuery 的工作方式做些什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 2016-05-04
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多