0

Why is Mongoose showing the deprecated warning after I have set the promise library?

Countless posts (example #1, example #2, etc.) say to set mongoose.Promise = global.Promise; to resolve this warning. I have even done it myself in the past! However, nothing I do prevents Mongoose from complaining about the promise library:

(node:54561) DeprecationWarning: Mongoose: mpromise (mongoose's default 
promise library) is deprecated, plug in your own promise library instead: 
http://mongoosejs.com/docs/promises.html

I'm using v4.8.7 with the following code:

var bodyParser  = require('body-parser'),
    config      = require('./config'),
    data        = require('./data'),
    express     = require('express')
    mongoose    = require('mongoose'),
    routes      = require('./routes');

mongoose.Promise = global.Promise;

var db  = mongoose.connection;
var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(routes);

db.once('open', function() {

    console.log('Database connected!');

    data.seeds.doSeed(function(){

        app.listen(3000, function() {
            console.log('Mongo example listening on port 3000!');
        });
    });
});

mongoose.connect(config.db.uri, config.db.options);
Community
  • 1
  • 1
G. Deward
  • 1,542
  • 3
  • 17
  • 30

1 Answers1

1

You are using the underlying MongoDB driver, from the documentation

Promises for the MongoDB Driver

The mongoose.Promise property sets the promises mongoose uses. However, >this does not affect the underlying MongoDB driver. If you use the >underlying driver, for instance Model.collection.db.insert(), you need to >do a little extra work to change the underlying promises library. Note >that the below code assumes mongoose >= 4.4.4.

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

    Band = db.model('band-promises', { name: String });

    db.on('open', function() {
      assert.equal(Band.collection.findOne().constructor, require('bluebird'));
    });

I think this is a answer you are asking for.

Community
  • 1
  • 1
Tolsee
  • 1,695
  • 14
  • 23
  • Thanks, but this is not helpful. The only difference, I can see, is you are using the `options` object to set the promise library. According to the MongooseJS docs, my syntax matches theirs identically: http://mongoosejs.com/docs/promises.html – G. Deward Mar 19 '17 at 15:16
  • I think you are not considering the fact that "The mongoose.Promise property sets the promises mongoose uses. However, >this does not affect the underlying MongoDB driver. If you use the >underlying driver, for instance Model.collection.db.insert(), you need to >do a little extra work to change the underlying promises library. Note >that the below code assumes mongoose >= 4.4.4" – Tolsee Mar 19 '17 at 17:09