jquery - 在 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 的数据是作为请求的结果获得的。这是导致此错误的原因吗?
提前致谢。
解决方案
似乎很少有人遇到与您目前相同的问题。看起来像服务器端的限制。
我会 :
- 使用分页系统限制从服务器发送到数据表的项目数。
如果我不能,我可以:
- 更改服务器的配置以增加 AJAX 响应的大小。
但要知道,第二种选择只会拖延问题,并不能解决问题。
https://datatables.net/forums/discussion/42566/is-there-a-maximum-size-of-a-json-response
推荐阅读
- r - 保留 R 中矩阵的左上角列
- python - 分别从列中获取值并通过标签显示 - Python
- javascript - 从服务器加载而不是本地加载时的传单和移动图块
- c# - 控制台应用程序发布并包含内容文件
- javascript - 为什么以下 JavaScript Promise 会返回所有电子邮件附件?
- javascript - 我收到 ReferenceError: html is not defined
- javascript - 重新排序 jquery 数组从给定位置开始
- c++ - 交叉编译时Jetson工具链文件夹结构和libgomp链接器错误
- vba - 如何从大型 Excel 文件中聚合行
- c++ - std::sort / 在测试代码中工作,但不能推导出模板