findById не возвращает результат.const course
объект равен нулю при каждом входе в систему.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mongo-exercises', { useNewUrlParser: true });
const courseSchema = new mongoose.Schema({
name: String,
author: String,
tags: [ String ],
date: Date,
price: Number,
isPublished: Boolean
});
const Course = mongoose.model('Course', courseSchema);
async function updateCourse(id){
const course = await Course.findById(id);
if(!course) return;
course.isPublished = true;
course.author = 'Another Author';
const result = await course.save();
console.log(result);
}
updateCourse('5a68fde3f09ad7646ddec17e');