Mongoose Promise error

后端 未结 4 1569
遇见更好的自我
遇见更好的自我 2021-01-19 02:57

This is the error which is still being thrown when saving even after adding native promise.

(node:5604) DeprecationWarning: Mongoose: mpromise (mongoo

相关标签:
4条回答
  • 2021-01-19 03:41

    I've had success getting rid of the message with this

    mongoose.Promise = Promise;
    
    0 讨论(0)
  • 2021-01-19 03:47

    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.

    0 讨论(0)
  • I have used bluebird for using promise with mongoose model functions node v6.9.4 :

    mongoose.Promise = require('bluebird');
    
    0 讨论(0)
  • 2021-01-19 04:02

    Upgrading Mongoose from 4.8.1 to 4.9.1 solved my problem.

    0 讨论(0)
提交回复
热议问题