i work by NODE.JS by express, and mongo , mongodb, and execute CRUD by them. i can do GET and CREATE new document, BUT i can't execute DELETE & UPDATE using ID by same utilities.
note: this id, is valid and exist in my database. i checked this.
when i try this code, i receive this message in console:
connected to MONGOdb...
null
my DELETE code is in belove:
const mymongoose = require('mongoose');
mymongoose.connect('mongodb://localhost/mongo-exercises')
.then(() => console.log('connected to MONGOdb...'))
.catch(er => console.error('could not connect to mongodb', er));
const courseSchema = new mymongoose.Schema({
name: String,
author: String,
tags: [String],
date: {type: Date, default: Date.now},
isPublished: Boolean,
price: Number
});
const Course = mymongoose.model('Course', courseSchema);
//Remove code:
async function removeCourse(id) {
const course = await Course.findByIdAndRemove(id);
console.log(course);
}
removeCourse('5a68ff090c553064a218a547');