0

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.

anshul
  • 661
  • 9
  • 27
  • 1
    you could look at this, its kinda duplicate: https://stackoverflow.com/questions/38138445/node3341-deprecationwarning-mongoose-mpromise?answertab=votes#tab-top – Saikat Chakrabortty Jan 19 '19 at 09:28
  • Possible duplicate of [(node:3341) DeprecationWarning: Mongoose: mpromise](https://stackoverflow.com/questions/38138445/node3341-deprecationwarning-mongoose-mpromise) – Alwaysblue Jan 19 '19 at 09:30
  • Which version of nodejs you are using? I use node 8. And I dont need to specify promise library, it takes the global one by default. – Jayadratha Mondal Jan 20 '19 at 03:03

2 Answers2

1

try using this code mate

var mongoose = require('mongoose');

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://10.7.0.3:27107/data/TodoApp'); 
ALPHA
  • 1,135
  • 1
  • 8
  • 18
-1

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.

Jayadratha Mondal
  • 759
  • 1
  • 10
  • 21
  • I am able to use ES-6 version of promise instead of bluebird, but unable to save it to my MongoDB database.i'm getting my second console.log message printing. – anshul Jan 20 '19 at 05:51
  • @AbhinavAnshul what is the error message. Print the error message & paste here. – Jayadratha Mondal Jan 20 '19 at 06:12
  • It worked, I had few files corrupted in MongoDB application as well as I use outdated Nodejs. Thank you so much for helping. – anshul Jan 20 '19 at 07:10