13

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.

Ivan Erlic
  • 391
  • 1
  • 4
  • 14

4 Answers4

31

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

mongoose.Promise = require('bluebird');
Johannes Merz
  • 3,252
  • 17
  • 33
14

From node 4.x you can just use ES6 promises:

const mongoose = require('mongoose');
mongoose.Promise = Promise;
olefrank
  • 6,452
  • 14
  • 65
  • 90
3

Here's an example that may help. Using es6 modules (instead of CommonJS require) this works for me:

// mongoose's Promise library is deprecated, using es6's: 
import es6Promise from 'es6-promise';
mongoose.Promise = es6Promise.Promise;
wojjas
  • 1,046
  • 1
  • 9
  • 21
1

you can refer to How to use mongoose Promise - mongo

the page content :

On this page:http://mongoosejs.com/docs/promises.html

The title is Plugging in your own Promises Library

Community
  • 1
  • 1
Mr.Thanks
  • 215
  • 3
  • 7