Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – (node:3341)DeprecationWarning:Mongoose:mpromise大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是triyng使用我的自定义方法在mongoose的顶部开发一个类,所以我扩展了mongoose与我自己的类,但当我调用创建一个新的汽车方法,它的工作,但它的地带和错误在这里我让你看到什么我想做。

我收到这个警告

(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 carscheR_823_11845@a = new scheR_823_11845@a({
  carName: String,availableSeats: number,createdOn: { type: Date,default: Date.Now },});
const driverscheR_823_11845@a = new scheR_823_11845@a({
 email: String,name: String,city: String,phonenumber: String,cars: [carscheR_823_11845@a],userId: {
   type: scheR_823_11845@a.Types.ObjectId,required: true,});
const DriverModel = mongoose.model('Driver',driverscheR_823_11845@a);

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

任何想法,我做错了什么?

解决方法

以下是我为什么清除这个问题,阅读文档后:
@L_607_12@

在doc中的例子是使用bluebird promise库,但我选择了与原生的ES6承诺。

在我@L_926_3@mongoose.connect的文件中:

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

[编辑:感谢@SylonZero在我的答案带来了性能缺陷。由于这个答案是如此之大,我觉得有责任做这个编辑,并鼓励使用蓝鸟,而不是本土承诺。请阅读他们更教育的答案。 ]]

大佬总结

以上是大佬教程为你收集整理的node.js – (node:3341)DeprecationWarning:Mongoose:mpromise全部内容,希望文章能够帮你解决node.js – (node:3341)DeprecationWarning:Mongoose:mpromise所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。