【问题标题】:Typer Error: Cannot read property 'length' of undefined打字机错误:无法读取未定义的属性“长度”
【发布时间】:2019-06-27 01:51:57
【问题描述】:

我正在创建一个 node.js 应用程序并实现调度程序应用程序。我正在关注这个演练:https://dhtmlx.com/blog/using-dhtmlxscheduler-with-node-js/

当我导航到 /data 页面时,它说无法读取未定义的属性“长度”。我去了github页面,逐字下载了app.js。

这是 app.js 部分抛出错误:

app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
    //set id property for all records
    for (var i = 0; i < data.length; i++)
        data[i].id = data[i]._id;

    //output response
    res.send(data);
});
});

【问题讨论】:

  • data 未定义,您检查是否有错误?将console.log(err) 放在 for 循环之前会得到什么?
  • Error occured with no callback to handle it while calling SkinCollection.insert Error: URL malformed, cannot be parsed
  • 这是我克隆的 git repo,仍然收到错误无法读取未定义的属性“长度”。 link

标签: javascript node.js mongodb dhtmlx-scheduler


【解决方案1】:

这个example 工作正常。我想,在您的情况下,mongoskin 由于某些原因无法连接到 mongodb。如果我更改这条路径mongodb://localhost/testdb 中的某些部分(出于测试目的,放置一些随机字符串),mongodb 将抱怨url 的问题,并且我会从节点js 收到错误TypeError: Cannot read property 'length' of undefined,因为有将不会从数据库中获取数据。

【讨论】:

  • 我刚刚开始工作。我正在使用 MongoDB 地图集,出于某种原因,我的连接字符串从 Short SRV 字符串切换到标准使其工作
猜你喜欢
  • 2020-01-24
  • 2015-05-08
  • 2020-06-02
  • 2015-02-05
  • 2017-11-25
  • 2021-02-26
  • 1970-01-01
  • 2022-11-12
  • 2022-01-13
相关资源
最近更新 更多