我试图通过 id 查找记录,但没有完成
var id = req.param('id');
var item = {
'_id': id
}
videos.find(item, function(error, response) {});
我已经给出了一个有效的 ID,但仍然无法获取,有人可以建议帮助吗?
最佳答案
有一个回调提供给 find()
但在上面的代码中,它没有可执行语句。而不是这个:
videos.find(item, function(error, response) {});
...做这样的事情:
videos.find(item, function(error, response) {
if (error) {
console.log(error); // replace with real error handling
return;
}
console.log(response); // replace with real data handling
});
关于node.js - 无法在 Mongoose 中按 id 找到记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41735607/