gpt4 book ai didi

javascript - ( Node :5700) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, 插入你自己的 Promise 库

转载 作者:行者123 更新时间:2023-12-01 01:19:30 25 4
gpt4 key购买 nike

我收到此警告:DeprecationWarning:Mongoose:mpromise(mongoose 的默认 promise 库)已弃用,请插入您自己的 promise 库。当我尝试在后端路由上的 MongoDb 中的模型上执行 .find 时,出现此错误。我不确定这意味着什么或如何解决它。

下面我显示了正在调用的导致此错误的路由。我很抱歉,我不太了解一般的 promise ,我不确定“妥协”是什么意思。

app.get("/search/search=:search&location=:location?", function (req, res) { console.log("我在家庭搜索后端")

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

}

});

我的代码正在运行,我只是担心弃用会在将来导致我的代码出现问题。如果没什么可担心的,请告诉我!

最佳答案

在定义了 mongoose.connect() 方法的 server.js 文件中。添加在其上方。

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

关于javascript - ( Node :5700) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, 插入你自己的 Promise 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54361927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com