(节点:3341)弃用警告:猫鼬:mpromise [英] (node:3341) DeprecationWarning: Mongoose: mpromise

查看:73
本文介绍了(节点:3341)弃用警告:猫鼬:mpromise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义方法在猫鼬的顶部开发一个类,因此我用自己的类扩展了猫鼬,但是当我调用创建一个新的car方法时,它可以工作,但是它的剥离和错误,在这里我让你看看我要做什么.

I'm trying to develop a class on the top of the mongoose with my custom methods, so I extended the mongoose with my own class but when I invoke to create a new car method it works but its strip and error, here I let you see what I'm trying to do.

我收到此警告

(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类的实例

driver is an instance of Driver class

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;
 }
}

关于我在做什么错的任何想法?

any thoughts about what Im doing wrong?

推荐答案

在阅读文档后,以下是我为解决此问题所做的工作: http://mongoosejs.com/docs/promises.html

Here's what worked for me to clear up the issue, after reading docs: http://mongoosejs.com/docs/promises.html

文档中的示例使用的是bluebird Promise库,但我选择使用本机ES6 Promise.

The example in the doc is using the bluebird promise library but I chose to go with native ES6 promises.

在我呼叫mongoose.connect的文件中:

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://10.7.0.3:27107/data/db');

这篇关于(节点:3341)弃用警告:猫鼬:mpromise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆