简体   繁体   中英

PUT method is working only 6 times in Node express app

I am using Mongodb as my database to update the value of variable. And I'm using node.js and express server.

Here is my code:

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 },
                              {}
                            ]
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }]
        )

This code is updating the variable only 6 times. Then I have to reload the app to update another 6 times.

What might be the problem?

I just found the problem. It is my server waiting for response. Browser limits the concurrent request limits to 6 or something. That is the problem.

Best way to do this is to end the response waiting by calling:

res.end()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM