Mongoose Promise error

后端 未结 4 1593
遇见更好的自我
遇见更好的自我 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: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.

提交回复
热议问题