mongoose:一系列的自定义实例
根据文件我可以做这样的事情:
var animalSchema = new Schema({ name: String, type: String }); animalSchema.methods.findSimilarTypes = function (cb) { return this.model('Animal').find({ type: this.type }, cb); }
假设我有另一个function:
animalSchema.methods.owner
,如果animalScheme.owner
是xyz,那么它将过滤search查询{..., owner: xyz}
有没有可能顺序使用实例? 我怎样才能做到这一点?
var animalSchema.findSimilarTypes().owner("xyz") ?
任何提示?
我相信这不能马上工作,因为原始函数findSimilarTypes
不会返回一个模式对象。
我猜你正在试图做一些jQuery如何工作。