简体   繁体   中英

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

I'm getting this warning: DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead. I got this error when I was trying to do a .find on a model in MongoDb on my backend route. I'm not sure what it means or how to address it.

Below I show the route that is being called that is causing this error. I apologize that i'm not that aware of promises in general, i'm not sure what they mean by "mpromise".

app.get("/search/search=:search&location=:location?", function (req, res) { console.log("I'm in home search back-end")

console.log(req.params.search);
console.log(req.params.location);

var resultObj = {
    search: req.params.search,
    location: {},
    results: []
}

if (req.params.location) {


    var apiKey = "AIzaSyBejz2PGLk2-SG6MI6FCEmyaCQG-7pPuuw"
    var query = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" + req.params.location + "&key=" + apiKey;
    var query2 = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + req.params.location + "&destinations=&key=" + apiKey;
    request(query, function (error, response, body) {
        if (!error && response.statusCode === 200) {
            // console.log(results)

                resultObj.location = JSON.parse(body).results;
                // resultObj.location = body
                var geo = resultObj.location[0].geometry.location
                console.log("I requested google maps api");
                console.log(geo);

            // $near: [geo.lat, geo.lng]



            Item.find({
                // $text: { $search: req.params.search }, 
                'geometry.coordinates': {
                    $geoWithin: {
                        $center: [[geo.lng, geo.lat], 20 / 3963.2 ]
                    }

                }



            })
                .populate('properties.itemReviews')
                // .skip(20)
                .limit(5000)

                .exec(function (err, results) {

                    if (err) {
                        console.log("searching users by location was not successful");
                        console.log(err);
                        res.json({ failedLocation: "This location does not exist" })
                    } else {
                        console.log("ive successfully searched users by location, below is results");
                        console.log(err)
                        console.log(results);
                        resultObj.geoResults = results
                        resultObj.finalResults = [];
                        resultObj.geo = geo;
                        res.json(resultObj)
                    }
                });

            } else {
                res.json({ error: "There was an error with your address" });
            }


    });



} else {
    res.json(resultObj);

}

});

My code is working, I'm just worried about a deprecation causing problems in my code in the future. If there is nothing to worry about, please let me know!

In the server.js file where you have defined mongoose.connect() method. Add above it.

mongoose.Promise = global.Promise; // Use this line.
mongoose.connect('mongodb://url', { useMongoClient: true }, function (err) {
    if (err) {
        console.log('not connected to data base');
    }
    else {
        console.log('Successfully Connected to database');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM