I am trying to set up my MongoDB database using mongoose but getting a deprecated warning "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 code for server.js file below:

var mongoose = require('mongoose');
mongoose.promise = require('bluebird');


// mongoose.promise = global.promise;
mongoose.connect('mongodb://localhost:27017/TodoApp');

var Todo = mongoose.model('Todo', {
  text: {
    type: String
  },
  completed: {
    type: Boolean
  },
  completedAt: {
    type: Number
  }
});

var newTodo = new Todo({
  text: 'Cook dinner'
});

newTodo.save().then((doc) => {
  console.log('Saved todo', doc);
}, (e) => {
  console.log('Unable to save todo')
});

I already tried to install bluebird and to use it as my third party promise but still getting the same error message.

2

There are 2 answers

3
Jayadratha Mondal On BEST ANSWER

You should use

mongoose.Promise = require('bluebird');

You are using

mongoose.promise = require('bluebird');

Also I think you are using older version of nodejs. I use node js 8 & mongoose takes global.Promise by default as nodejs 8 comes with native Promise.

0
ALPHA On

try using this code mate

var mongoose = require('mongoose');

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://10.7.0.3:27107/data/TodoApp');