我正在努力为 Mongoose 模型创建模型函数。我在这里定义了一个方法:
Schema.listingSchema.method('applyPrice', function() {
this.price = priceFromString(this.title);
});
我在这里访问它:
var listing = new Listing();
// assign all relevant data
listing.title = title;
...
// pull the price out of the title and description
listing.applyPrice(listing);
在哪里
Listing = mongoose.model('Listing', Schema.listingSchema);
我收到错误:
TypeError: Object #<model> has no method 'applyPrice'
任何人都可以看到这个问题吗?