0

I’m creating a node.js app and implementing the scheduler app. I’m following this walkthrough: https://dhtmlx.com/blog/using-dhtmlxscheduler-with-node-js/

When I navigate to the /data page, it says cannot read property 'length' of undefined. I went to the github page and downloaded app.js word for word.

Here is app.js portion throwing error:

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);
});
});
tyler
  • 125
  • 4
  • 14
  • `data` is undefined, have you checked if there was an error? What do you get when you put `console.log(err)` before the for-loop? – Patrick Hund Feb 02 '19 at 20:54
  • `Error occured with no callback to handle it while calling SkinCollection.insert Error: URL malformed, cannot be parsed` – tyler Feb 02 '19 at 21:03
  • here is the git repo I cloned, still getting the error Cannot read property 'length' of undefined. [link](https://github.com/DHTMLX/node-scheduler-demo) – tyler Feb 02 '19 at 22:19

1 Answers1

0

This example works fine. I guess, in your case, mongoskin fails to connect to mongodb for some reasons. If I change some parts in this path mongodb://localhost/testdb (for testing purpose, put some random string) , mongodb will complain about problem with url, and I'll get an error TypeError: Cannot read property 'length' of undefined from node js, because there will be no data fetched from database.

Vadi
  • 3,279
  • 2
  • 13
  • 30
  • I just got this to work. I’m using MongoDB atlas and for some reason switching my connection string from the Short SRV string to standard made it work – tyler Feb 03 '19 at 00:10