首页 > 解决方案 > 在 Node js 应用程序 + MongoDb 中加载数据时出现错误

问题描述

我在 UI 中呈现数据时遇到问题。使用 NODE JS 应用程序,Mongo DB 是后端。这是使用的代码片段。

employee.get('/results', checkRole(), function (req, res) {
 
  employeeResultModel
    .find({})   
    .then(doc => {
      res.send(doc);
    })
    .catch(err => {
      log.error('Error occurred while fetching employee from the database', err);
    });
});

mongo collection 员工有 8040 条记录来自db.getCollection('employee').find({}).count()

在控制台中看到的错误如下,

DataTables warning: table id=executionResult - Ajax error. For more information about this error, please see http://datatables.net/tn/7

同样在调试器控制台中

jQuery-3.4.1.min.js:2 GET https://localhost/ci/results?_=1607595446722 500 (Internal Server Error)

加载包含 460 条记录的早期员工集合时,没有发现任何问题。

我正在寻求帮助,让我知道这个问题是否是由于集合中的大量数据造成的,因此发生了此故障,或者我的代码存在问题。

员工集合中已提供索引 - “_id”

从 Debugger 的“Network”选项卡中,可以看到 15MB 的数据是作为请求的结果获得的。这是导致此错误的原因吗?

提前致谢。

标签: jquerynode.jsmongodb

解决方案


似乎很少有人遇到与您目前相同的问题。看起来像服务器端的限制。

我会 :

  • 使用分页系统限制从服务器发送到数据表的项目数。

如果我不能,我可以:

  • 更改服务器的配置以增加 AJAX 响应的大小。

但要知道,第二种选择只会拖延问题,并不能解决问题。


https://datatables.net/forums/discussion/39332/2-datatables-with-ajax-throwing-ajax-error-for-datasets-over-certain-size

ajax 错误 500 和 MVC 中的内部服务器错误

https://datatables.net/forums/discussion/42566/is-there-a-maximum-size-of-a-json-response


推荐阅读