我正在尝试使用自定义方法在猫鼬的顶部开发一个类,因此我用自己的类扩展了猫鼬,但是当我调用创建一个新的car方法时,它可以工作,但是它的剥离和错误,在这里我让你看看我要做什么。
我收到此警告
(node:3341) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
我做完之后
driver.createCar({
carName: 'jeep',
availableSeats: 4,
}, callback);
driver是Driver类的实例
const carSchema = new Schema({
carName: String,
availableSeats: Number,
createdOn: { type: Date, default: Date.now },
});
const driverSchema = new Schema({
email: String,
name: String,
city: String,
phoneNumber: String,
cars: [carSchema],
userId: {
type: Schema.Types.ObjectId,
required: true,
},
createdOn: { type: Date, default: Date.now },
});
const DriverModel = mongoose.model('Driver', driverSchema);
class Driver extends DriverModel {
getCurrentDate() {
return moment().format();
}
create(cb) {
// save driver
this.createdOn = this.getCurrentDate();
this.save(cb);
}
remove(cb) {
super.remove({
_id: this._id,
}, cb);
}
createCar(carData, cb) {
this.cars.push(carData);
this.save(cb);
}
getCars() {
return this.cars;
}
}
关于我在做什么错的任何想法?
mongoose.Promise = global.Promise
,您就不会再收到该警告了。” github.com/Automattic/mongoose/issues/…–