我正在研究快递和猫鼬,并且已经做了mongoose statics
。
const mongoose = require('mongoose');
const trainerSchema = require('./trainer.model');
trainerSchema.statics = {
create : (data, cb) => {
const trainer = new this(data);
trainer.save(cb);
},
get: (query, cb) => {
this.find(query, cb);
},
getByName: (query, cb) => {
this.find(query, cb);
},
update: (query, updateData, cb) => {
this.findOneAndUpdate(query,
{$set: updateData},{new: true}, cb);
},
delete: (query, cb) =>{
this.findOneAndDelete(query,cb);
}
}
const trainerModel = mongoose.model('Trainer',
trainerSchema);
module.exports = trainerModel;
但是每当我尝试创建trainer
模式时,都会出现此错误:TypeError: this is not a constructor
我不知道为什么会这样,因为我认为这是模式架构的回溯。