Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

498
Views
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 answers
Answer question

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 Report

0

Upgrading Mongoose from 4.8.1 to 4.9.1 solved my problem.

over 4 years ago · Santiago Trujillo Report

0

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

mongoose.Promise = Promise;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!