Mongoose's default promise library is deprecated in MEAN stack

后端 未结 4 1367
北海茫月
北海茫月 2020-12-19 05:19

I\'m trying to start a MEAN-stack server, however I\'m getting this error msg:

Mongoose: mpromise (mongoose\'s default promise library) is deprecated,

4条回答
  •  猫巷女王i
    2020-12-19 06:11

    Latest mongoose library, do not use any default promise library. And from Mongoose v 4.1.0 you can plug in your own library.

    If you are using mongoose library(not underlying MongoDB driver) then you can plug in promise library like this:

    //using Native Promise (Available in ES6)
    mongoose.Promise = global.Promise;
    
    //Or any other promise library
    mongoose.Promise = require('bluebird');
    
    //Now create query Promise
    var query = someModel.find(queryObject);
    var promise = query.exec();

    If you are using MongoDB Driver then you will need to do some extra effort. Because, mongoose.Promise sets the Promise that mongoose uses not the driver. You can use the below code in this case.

    // Use bluebird
    var options = { promiseLibrary: require('bluebird') };
    var db = mongoose.createConnection(uri, options);

提交回复
热议问题