Mongoose Promise Error

This is a mistake that is still thrown when saving even after adding your own promises.

(node: 5604) DeprecationWarning: Mongoose: mpromise (default mongoose promise library) is deprecated, instead add your own promise library: 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 tried both bluebird and q, still have not found a fix. Below is the code, when I save it, the following failure warning appears.

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 occurs in the new mongoose version, which is 4.8.1, but works fine in mongoose version 4.7.6.

+4
source share
4

mongoose.Promise = global.Promise; mongoose.connect(...), .

, mongoose :

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);
});

mongoose ( ), mongoose.Promise = global.Promise; , .

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

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

, .

+2

mongoose.Promise = Promise;
0

I used bluebird to use promises with the mongoose node v6.9.4 model functions:

mongoose.Promise = require('bluebird');
0
source

I have the same problem with Mongoose 4.8.1, updating to 4.9.1 solved my problem.

0
source

Source: https://habr.com/ru/post/1668255/


All Articles