Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

500
Vistas
Mongoose Promise error

This is the error which is still being thrown when saving even after adding native promise.

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

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://127.0.0.1/optimusCP')
    .then(function () {
        console.log('Connected to MONGOD !!');
    }).catch(function (err) {
        console.log('Failed to establish connection with MONGOD !!');
        console.log(err.message);
    });

I have tried both bluebird & q, still haven't found a fix for this. Below is the code when I save this, the following deprecation warning shows up..

var user = new User();
        user.email = req.body.email;
        user.password = hash;
        user.save()
            .then(function (user) {
                console.log(user);
            })
            .catch(function (err) {
                console.log(err);
            });

This error is happening on the new version of mongoose which is 4.8.1, but working fine on 4.7.6 mongoose version.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Despite using mongoose.Promise = global.Promise; before mongoose.connect(...), I had the same warning.

I discovered, that I initialized mongoose connection in one file:

import mongoose from 'mongoose';

...

// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(mongoUri, mongoOptions);
mongoose.connection.on('error', (err) => {
  console.error(`MongoDB connection error: ${err}`);
  process.exit(1);
});

But I imported mongoose in another file too (where mongoose scheme was described), so I added mongoose.Promise = global.Promise; in second file too, as a result of it, the warning disappeared.

import mongoose, { Schema } from 'mongoose';
mongoose.Promise = global.Promise;

const UserSchema = new Schema({ ... });

May be you have the same case.

over 4 years ago · Santiago Trujillo Denunciar

0

Upgrading Mongoose from 4.8.1 to 4.9.1 solved my problem.

over 4 years ago · Santiago Trujillo Denunciar

0

I've had success getting rid of the message with this

mongoose.Promise = Promise;
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda