【问题标题】:Error seen when loading data in Node js application + MongoDb在 Node js 应用程序 + MongoDb 中加载数据时出现错误
【发布时间】:2021-03-21 18:59:22
【问题描述】:

我在 UI 中呈现数据时遇到问题。使用节点 JS 应用程序和 Mongo DB 是后端。 这是sn-p使用的代码。

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 集合员工从db.getCollection('employee').find({}).count() 获得了 8040 条记录

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

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”

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

提前致谢。

【问题讨论】:

    标签: jquery node.js mongodb


    【解决方案1】:

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

    我愿意:

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

    如果我不能,我可以:

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

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


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

    ajax error 500 & Internal Server Error in MVC

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

    【讨论】:

    • 我浏览了关于增加 json 响应 大小的共享链接。是否有任何选项可以设置 Node JS 应用程序的 json 响应大小。
    • 经过继续分析,我能够解决错误。感谢您的帮助..
    • @RahulMG 我很高兴你做到了!您可以发布您发现的内容以帮助有类似问题的其他人吗?
    • 渲染代码需要一个集合数据中缺少的值。例如,该集合包含employee_id、employee_name、employee_designation。但是在我在js 中的渲染代码中,我试图获取导致此问题的employee_address。抱歉发布这个问题,因为我觉得这是一个愚蠢的错误,我应该分析更多在发布此查询之前..
    猜你喜欢
    • 2022-10-07
    • 2021-09-05
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2018-10-18
    • 2018-10-19
    相关资源
    最近更新 更多