Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我在处理批处理请求时遇到数据库问题_Node.js_Mongodb_Express - Fatal编程技术网

Node.js 我在处理批处理请求时遇到数据库问题

Node.js 我在处理批处理请求时遇到数据库问题,node.js,mongodb,express,Node.js,Mongodb,Express,当我处理对ExpressJS应用程序的批处理请求时,数据未按预期保存 我有以下连续执行以运行的端点: app.post("/save", function1, function2) ... exports.function1 = async (req, res, next) => { //... await data1.save() } exports.function2 = async (req, res, next) => {

当我处理对ExpressJS应用程序的批处理请求时,数据未按预期保存

我有以下连续执行以运行的端点:

app.post("/save", function1, function2)



...


exports.function1 = async (req, res, next) => {
     //...
  await data1.save()
}

exports.function2 = async (req, res, next) => {
         //...
     await data2.save()
    }
基本上,这两个函数的目的都是通过向现有文档中添加新信息来将数据保存到我的mongoDb数据库中。基本上,典型的数据类型如下:

{
  "key1" : "value1",
  "key2" : "value2",
  "key3" : {
     "subKey1" : "subValu1",
     "subKey2" : "subValue2",
  }
}
当我手动发出单个请求或执行非常小的批处理(如5个批处理请求)时,数据按预期保存

但是,如果我执行了一批30多个请求,所有请求都会失败,而不是将数据保存在文档中,而是出现了一个
null
。即使我将30个请求的执行间隔10秒

经过几天的调查,我真的说不出那是什么原因


有什么建议吗?

在函数中,在最后一行调用
next()

我已经在实际代码中调用了next,即使上面的示例中没有显示它。所以我认为问题出在别的地方。正如我所说,只要我提出个人要求或小批量要求,一切都是好的。当我发出一大批十几个/数百个请求时,情况会变得更糟。您是在使用连接池还是在功能中创建新连接我不是在使用连接池,而是在声明任何路由之前,执行一些基本操作,如
wait xxxx.findById()
wait xxxxx.save()
在开始时打开连接,未捕获异常中的紧密连接这实际上已经在my
mongoose.js
中设置为它。所以我认为问题不在于此。基本上,mongoose会监听错误,如果是,连接就会关闭。