首页 > 解决方案 > 查找查询显示所有课程列表和相关信息,但在使用 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');

标签: node.jsmongoose

解决方案


推荐阅读