![](/img/trans.png)
[英]“mpromise (mongoose's default promise library) is deprecated” in Typescript Application
[英](node:5700) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead
我收到此警告:DeprecationWarning:貓鼬:mpromise(貓鼬的默認諾言庫)已過時,請插入您自己的諾言庫。 我在后端路線上嘗試在MongoDb中的模型上執行.find時遇到此錯誤。 我不確定這意味着什么或如何解決。
下面,我顯示了導致此錯誤的正在調用的路由。 我很抱歉,我通常並不了解諾言,我不確定“妥協”是什么意思。
app.get(“ / search / search =:search&location =:location?”,功能(要求,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');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.