什么是:“元素延伸超过对象的末尾” ?我该如何修复它?
我收到错误:在此路线中“元素延伸到对象末尾”。我用谷歌搜索但没有找到太多东西。有谁知道我该如何解决它以及问题到底是什么?
谢谢!
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');
}
});
});
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');
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您只是使用了错误的方法,
findById
仅通过ObjectID进行搜索。在您的上下文中(我真的不知道您正在发送 req.params.name),我认为您不应该通过 ID 进行搜索。尝试使用
findOne
(将 [yournamefield] 替换为 Item 模型中相应的字段名称):Maybe you are just using the wrong method,
findById
only 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
findOne
instead (replace [yournamefield] with the corresponsing fieldname inside your Item model):