Ivan Erlic Ivan Erlic - 3 months ago 32
Node.js Question

"mpromise (mongoose's default promise library) is deprecated" error when testing

For a while I have been getting this error and I decided to fix it today but after an hour trying to fix it I can find the solution.

When I test my mongoose User model this error/warning is generated:

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


Here is my test:

1 var assert = require('chai').assert;
2 var mongoose = require('mongoose');
3 var clearDB = require('mocha-mongoose')(require('../../config/database').uri, { skip: ['workouts'] });
4 var database = require('../../config/database').connect;
5
6 var User = require('../../app/models/user');
7 var user = new User({});
8
9 var req_body = {
10 username: "garyvee",
11 email: "gary@vaynermedia.com",
12 password: "secret"
13 };
14
15 describe('User', function() {
16 beforeEach(function(done) {
17 user.username = "johnsmith";
18 user.email = "john@gmail.com";
19 user.password = "secret";
20 done();
21 });
22
23 it('can be saved', function() {
24 return user.save(function(err: any) {
25 assert.isNull(err);
26 })
27 });
28 });


I think it has something to do with the
.save
but I don't know how to fix it. Can someone help me and tell me how to fix it so that error/warning isn't shown.

Answer

You need to plugin a promise library (q, bluebird, the es6 one...)

mongoose.Promise = require('bluebird');
Comments