This is the error which is still being thrown when saving even after adding native promise.
(node:5604) DeprecationWarning: Mongoose: mpromise (mongoo
I've had success getting rid of the message with this
mongoose.Promise = Promise;
Despite using mongoose.Promise = global.Promise;
before mongoose.connect(...)
, I had the same warning.
I discovered, that I initialized mongoose connection in one file:
import mongoose from 'mongoose';
...
// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(mongoUri, mongoOptions);
mongoose.connection.on('error', (err) => {
console.error(`MongoDB connection error: ${err}`);
process.exit(1);
});
But I imported mongoose
in another file too (where mongoose scheme was described), so I added mongoose.Promise = global.Promise;
in second file too, as a result of it, the warning disappeared.
import mongoose, { Schema } from 'mongoose';
mongoose.Promise = global.Promise;
const UserSchema = new Schema({ ... });
May be you have the same case.
I have used bluebird for using promise with mongoose model functions node v6.9.4 :
mongoose.Promise = require('bluebird');
Upgrading Mongoose from 4.8.1 to 4.9.1 solved my problem.