Audel O. Gutierrez Audel O. Gutierrez - 2 months ago 352
Node.js Question

(node:3341) DeprecationWarning: Mongoose: mpromise

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

I'm getting this warning

(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


after I do

driver.createCar({
carName: 'jeep',
availableSeats: 4,
}, callback);


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?

Answer

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

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

In the file where I'm calling mongoose.connect:

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