1

I am using popular fix from Internet, but it still ain't working... here is my code:

var Lobby = require('../models/lobbies-model');
var mongoose = require('mongoose');

mongoose.Promise = require('bluebird');
mongoose.connect('localhost:27017/mydb');
var lobbies = [
    new Lobby({
        nickname: 'Nickname1',
        status: "Status1",
    }),
    new Lobby({
        nickname: 'Nickname2',
        status: "Status2",
    })
];

var done = 0;
for (var i = 0; i < lobbies.length; i++) {
    lobbies[i].save(function(err, result) {
        done++;
        console.log(result);
        if (done === lobbies.length) {
            exit();
        }
    });
}

function exit() {
    mongoose.disconnect();
}

And have an error in my console and my result...

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

How to fix that error?

Bim Bam
  • 429
  • 1
  • 6
  • 17
  • Try moving the `var Lobby = require('../models/lobbies-model');` line after you set `mongoose.Promise`. – JohnnyHK Mar 08 '17 at 03:55

1 Answers1

3

As stated here https://github.com/Automattic/mongoose/issues/4291#issuecomment-230312093 a workaround is to use mongoose.Promise = global.Promise; before the connect:

  mongoose.Promise = global.Promise; // ADD THIS
  mongoose.connect('localhost:27017/mydb');
michelem
  • 14,430
  • 5
  • 50
  • 66