node.js - PUT 方法在 Node express 应用程序中仅工作 6 次
问题描述
我使用 Mongodb 作为我的数据库来更新变量的值。我正在使用 node.js 和 express 服务器。
这是我的代码:
router.route("/update/").put( async (req, res) =>{
const count_update = {
date: new Date(),
count: req.body.count
}
var searchDate = count_update.date.toISOString().slice(0,10);
const auth = req.currentUser;
if (auth) {
try{
await User.updateOne(
{ id: auth.uid },
[{
$set: {
count: {
$cond: [
{
$gt: [searchDate, { $substr: [{ $last: "$count.date" }, 0, 10] }]
},
{
$concatArrays: [
"$count",
[{ date: count_update.date, count: count_update.count }]
]
},
{
$map: {
input: "$count",
in: {
$mergeObjects: [
"$$this",
{
$cond: [
{
$eq: ["$$this.date", { $last: "$count.date" }]
},
{ count: count_update.count },
{}
]
}
]
}
}
}
]
}
}
}]
)
此代码仅更新变量 6 次。然后我必须重新加载应用程序才能再更新 6 次。
可能是什么问题?
解决方案
我刚刚发现了问题。这是我的服务器等待响应。浏览器将并发请求限制限制为 6 或其他东西。那就是问题所在。
最好的方法是通过调用结束响应等待:
res.end()
推荐阅读
- python - python numpy创建数据集列:仅根据条件添加值,否则为null
- excel - 如何根据具有可变位置的另一个单元格设置单元格值
- reactjs - 如何使用 React 测试库测试 Material UI 选择组件
- python - 在 Python (Selenium) 中从 CSV 文件读取和写入变量
- reactjs - 无法从 Spring Boot 应用程序在浏览器中设置 HTTP Cookie
- css - 使用 CSS 网格重复模拟内联块,但防止占用未使用的空白
- data-science - 这个 P 论点有什么问题
- javascript - 如何让 babel-node 将 Workers 引用的文件转换为 commonjs?(就像 babel 一样)
- php - 想要将 quickbooks 桌面与 php 集成
- firebase - Firebase 实时数据库连接作为流可以保持多长时间?