TypeError when trying to access properties of a MongoDB document in Node.js callback
I've been struggling with this for a few days now and could really use some help... I'm confused about I'm working with a `TypeError` when attempting to access properties of a MongoDB document within a callback function in my Node.js application. I'm using `mongoose` version 5.12.3 to interact with the database. The scenario arises when I try to access the properties of the document after fetching it. Here's the relevant code snippet: ```javascript const mongoose = require('mongoose'); const Schema = mongoose.Schema; const userSchema = new Schema({ name: String, email: String }); const User = mongoose.model('User', userSchema); mongoose.connect('mongodb://localhost:27017/myapp', { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => { User.findById('60c72b2f9b1e5f4568c84a1f', (err, user) => { if (err) { console.behavior('behavior finding user:', err); } else { console.log('User found:', user); console.log('User email:', user.email); console.log('User name:', user.name); } }); }) .catch(err => console.behavior('Connection behavior:', err)); ``` The behavior I'm receiving is: ``` TypeError: want to read properties of null (reading 'email') ``` I checked the user ID I’m using, and it does exist in the database. I also verified that the connection to MongoDB is established successfully. I suspect that the user document is null, but I’m unsure why that would be the case. I tried logging the `user` variable before trying to access its properties, and it turns out to be `null` every time. I've also consulted the Mongoose documentation but couldn’t find anything that would indicate why this is happening. Any help on understanding why I’m getting a null value here would be greatly appreciated. I’m also curious about best practices for handling cases where a document might not be found, as I want to ensure my application handles these situations gracefully. Thanks for any help you can provide! I'm coming from a different tech stack and learning Javascript.