node.js - 无法在 Mongoose 中按 id 找到记录

标签 node.js express mongoose meanjs

我试图通过 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/

相关文章:

javascript - Mongoose 预保存 Hook 中的异步功能不起作用

node.js - 在 Node.JS 中是否有管理简单博客的模块?

node.js - NodeJS : Promise won't catch thrown exceptions

javascript - 使用来自客户端的信息进行 Node Js/Express api 调用

javascript - Express.js 中设置和获取 cookie 失败

javascript - 将自定义对象的 Mongoose PUT 实现到复杂模式中时出现问题

angularjs - 平均堆栈身份验证 - 最佳实践

javascript - await 不是保留字

node.js - Mongoose 批量插入错误

node.js - 显示 Mongoose 模型的多个验证错误