Warning from Nodejs Mongoose

2

This warning appears on the console:

  

(node: 5627) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: link

I tried everything so that it does not appear anymore. Does anyone know how to fix it?

var express = require('express');
var bodyParser = require('body-parser');
var assert = require('assert');
var User = require("./models/user").User;
var app = express();

app.use("/estatico", express.static('public'));

app.use(bodyParser.json()); //para peticiones application/json
app.use(bodyParser.urlencoded({extended: true}));

app.set("view engine", "jade");

app.get('/', function(req, res){
 res.render("index");
});

app.get('/login', function(req, res){
    User.find(function(err,doc) {
        console.log(doc);
        res.render("login");
    })

});

app.post('/users', function(req, res){
var user_login = new User({email: req.body.email, 
                           password: req.body.password,
                           password_confirmation: req.body.password_confirmation,
                           username: req.body.username
                          });

promise = user_login.save();

console.log(assert.ok(promise instanceof require('mpromise')));

return promise.then(function(us) {
    res.send("Datos guardados")
},function(err) {
    if(err) {
        console.log(String(err));
        res.send("Los datos no han sido guardados")
    };
})

});

app.listen(8080);

The code works, saves the data in case the form is completed correctly and throws the errors in case the form is not completed correctly, but why the warning?

    
asked by Emanuel Mamani 16.07.2016 в 20:48
source

2 answers

2

Viewing the documentation of link It has helped me in something

In the example of the documentation you are using the bluebird promises library, but I prefer to use the native promises of ES6.

In the file where you are calling mongoose.connect you must place the following:

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/baseDatos');
    
answered by 05.10.2016 в 03:12
1

It works correctly because it is not an error, but a warning that one of the dependencies of Mongoose, in this case, its own specification of Promises is deprecated and recommends using another library of Promises .

Documentation :

  

While mpromise is sufficient for basic cases, users   Advanced users may want to use their favorite Promises library as   bluebird or just use the native Promises library in ES6.   You should only specify the value of the mongoose.Promise variable for qe   point to the Promise Object's constructor and moongoose will use it.

var query = Band.findOne({name: "Guns N' Roses"});

// Uso de Promises nativo
mongoose.Promise = global.Promise;
assert.equal(query.exec().constructor, global.Promise);

// Uso de bluebird
mongoose.Promise = require('bluebird');
assert.equal(query.exec().constructor, require('bluebird'));

// Uso de Q.
mongoose.Promise = require('q').Promise;
assert.ok(query.exec() instanceof require('q').makePromise);
    
answered by 18.07.2016 в 14:56