FG
๐Ÿ’ป Software๐Ÿ—„๏ธ DatabasesMongoDB

DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated with 4.8.0 and 4.8.1

Fresh3 days ago
Mar 14, 20260 views
Confidence Score55%
55%

Problem

With mongoose versions 4.8.0 and 4.8.1 (node version is 6.9.5 and MongoDB version is 3.2.11) the following warning is generated the first time the save of a document occurs after starting the application (the warning does not appear when the same code is executed subsequent times after the first time while the application is still running, however, if the application is closed and restarted, then the first time a document save occurs after the application has been started the warning is generated): > DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html This issue does not appear when using the exact same application code with mongoose versions 4.7.9 and earlier. The code that sets up the mongoose connection is as follows: `// Set up mongoose and DB connection var mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); mongoose.connect('mongodb://localhost:27017/basedir', {server: { poolSize: 5 }});`

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Replace Deprecated mpromise with Bluebird in Mongoose Setup

Low Risk

The warning occurs because Mongoose versions 4.8.0 and 4.8.1 have deprecated their default promise library, mpromise. The application is still using the default promise library instead of an alternative like Bluebird, which is explicitly set in the code. This leads to the deprecation warning being triggered on the first document save after starting the application.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Install Bluebird

    Ensure that Bluebird is installed in your project as it will be used as the promise library for Mongoose.

    bash
    npm install bluebird
  2. 2

    Update Mongoose Connection Code

    Modify the Mongoose connection setup to explicitly set Bluebird as the promise library before connecting to the database.

    javascript
    var mongoose = require('mongoose');
    mongoose.Promise = require('bluebird');
    mongoose.connect('mongodb://localhost:27017/basedir', {server: { poolSize: 5 }});
  3. 3

    Test Document Save

    After making the changes, run your application and attempt to save a document to the database. This will help confirm that the deprecation warning no longer appears.

    javascript
    const MyModel = mongoose.model('MyModel', new mongoose.Schema({ name: String }));
    const doc = new MyModel({ name: 'Test' });
    doc.save();
  4. 4

    Check for Deprecation Warning

    Observe the console output during the first document save after restarting the application. Ensure that the DeprecationWarning does not appear.

    bash
    No code required

Validation

Confirm that the application runs without the DeprecationWarning during the first document save after a restart. Additionally, check that all functionalities relying on Mongoose promises work as expected.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodmhelp-wantedneeds-clarification