javascript - 如何避免 OVER_QUERY_LIMIT nodejs
问题描述
每次当我想在我的数据库中创建新位置时,我都会遇到这个错误,我试图实现 setTimeout() 来避免这种情况,但如果我做得正确,我不会感到沮丧。有什么建议吗?
router.post("/",middleware.isLoggedIn ,upload.single("image"),function(req, res){
geocoder.geocode(req.body.place.location, function(err, data){
while(status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
{
setTimeout(3000);
}
if ( err){
req.flash("error", err.message);
console.log("error");
return res.redirect("back");
}
req.body.place.lat = data[0].latitude;
req.body.place.lng = data[0].longitude;
//cloudinary configuration
cloudinary.uploader.upload(req.file.path, function(result){
// add cloudinary url for the image to the campground object under image property
req.body.place.image = result.secure_url;
// add author to campground
req.body.place.author = {
id: req.user._id,
username: req.user.username
};
Place.create(req.body.place, function(err, newlyCreated){
if(err){
res.send(err);
}else{
res.redirect("/");
}
});
});
});
});
解决方案
“收到状态码为 OVER_QUERY_LIMIT 的响应后,您的应用程序应确定已超出哪个使用限制。这可以通过暂停 2 秒并重新发送相同的请求来完成。如果状态码仍为 OVER_QUERY_LIMIT,则您的应用程序发送的请求过多每天。否则,您的应用程序每秒发送的请求太多。”
您的第一步需要是 2 秒超时来确定原因。如果每秒太多,请减少直到不再出现错误。
光盘&
推荐阅读
- jsf - Primefaces columnGroup 无法正确呈现
- javascript - Asp.net 在创建新类别时添加重复条目
- css - React Bulma 移动导航栏未按预期工作
- spartacus-storefront - 斯巴达克斯选择性推车
- javascript - 在 MVC 中将大数据从视图发送到控制器
- python - 您可以在 PySimpleGUI 表对象的行内添加隐藏值吗?
- django - 如何修复 Nginx 502 错误网关?-- Django 谷歌应用部署
- c# - 有什么方法可以更改代码中的 Fluent WPF 值?
- javascript - 在 jquery 中获取除特定类或 id 之外的文本
- oracle - Oracle 触发器手动插入