簡體   English   中英

PUT 方法在 Node express 應用程序中僅工作 6 次

[英]PUT method is working only 6 times in Node express app

我使用 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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM