3
У меня есть общий метод, который мне нужно реализовать для всех моделей. Сейчас я делаю это для каждой модели:Mongoose - Как создать общий метод для всех моделей?
var Product = module.exports = mongoose.model('Product', ProductSchema);
module.exports.flush = function (filename, cb) {
"use strict";
var collection = require(filename);
// todo: reimplement with promises
this.remove({}, function (err) {
if (err) {
console.log(err);
}
else {
this.create(collection, cb);
}
}.bind(this));
};
Как добавить этот метод, чтобы он существовал для всех моделей?
Так здорово так просто! Спасибо! – erGo