node.js - 查找查询显示所有课程列表和相关信息,但在使用 findById(id) 时,无法找到课程
问题描述
查找查询显示所有课程列表和相关信息,但是在使用 findById(id) 时,无法找到课程。
async function getCourse() {
const course = await Course.find({});
console.log(course);
}
getCourse()
async function updateCourse(id) {
const course = await Course.findById(id);
if (!course) return console.log("course not found");
course.name = 'sagar';
course.author = 'sagar';
const result = await course.save();
console.log(result);
}
updateCourse('5a68fde3f09ad7646ddec17e');
解决方案
推荐阅读
- c++ - 如何打印指针的地址?
- react-native - react-native navigation v2 - 对象作为 React 子项无效
- c# - Winform Datagridview 不显示数据
- java - 如何确保 Oracle 会话已关闭?
- sql - 如何根据每日股票报告为股票突变编写 SQL
- python - Python - 从没有方括号的字符串中提取数字
- java - timepicker 不显示仅小时棒棒糖版本 5.1.0
- java - java.time:如何验证日历周
- c++ - 在转换为 PUCHAR 并打印到控制台时,硬编码字符串给出的结果与从控制台读取的字符串不同
- java - XML 验证 - 未声明元素