Menu
I’m trying to use the findById method in mongoose, and I keep getting a null object from my console.log
import mongoose from "mongoose";
const idNum = '5a68fe2142ae6a6482c4c9cb';
mongoose.connect('mongodb://localhost/mongo-exercises')
.then(()=> console.log('Connected to MongoDB...'))
.catch(err=>console.error('Could not connect...'));
const courseSchema = mongoose.Schema({
tags: [ String ],
date: { type: Date, default: Date.now },
name: String,
author: String,
isPublished: Boolean,
price: Number
});
const Course = mongoose.model('Course', courseSchema);
async function showCourse(){
const course = await Course.findById(idNum).exec;
console.log(course);
};