I’m getting the error: “Element extends past end of object” in this route. I googled it but didn’t find much of anything. Does anyone know how I can fix it and what exactly the problem is?
Thanks!
app.get('/item/:name', function(req, res) {
// console.log("Ok, we\'re in app.get \'item/:name\', let's debug");
console.log(req.params.name); //== "something" here
Item.findById(req.params.name, function(err, doc) {
debugger;
if (err){
console.log(err); // =="Element extends past end of object"
res.send(err);
}
else {
console.log(" in the app.get/item:name db.query. The item is: " + item);
// debugger;
res.render('items/view');
}
});
});
Maybe you are just using the wrong method,
findByIdonly searches by ObjectID. In your context (i don’t really know that you are sending in req.params.name), i don’t think you should be searching by ID.Try using
findOneinstead (replace [yournamefield] with the corresponsing fieldname inside your Item model):