Ad
Typer Error: Cannot Read Property 'length' Of Undefined
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);
});
});
Ad
Answer
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.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad