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 i
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');
[EDIT: Thanks to @SylonZero for bringing up a performance flaw in my answer. Since this answer is so greatly viewed, I feel a sense of duty to make this edit and to encourage the use of bluebird
instead of native promises. Please read the answer below this one for more educated and experienced details. ]
did you try this? For Example :
const mongoose = require('mongoose')
mongoose.Promise = global.Promise // <--
const Schema = mongoose.Schema
const UserSchema = new Schema({
name: String,
})
const User = mongoose.model('user', UserSchema)
module.exports = User
if you create a model from a mongoose instance who's promise wasn't redefined - every query on this model would throw the warning.